PageSourceSearch

https://aspirebm.co.uk/assets/BlogEditor-B1mRAcYV.js

js aspirebm.co.uk collected 2026-10-05 05:16:00 UTC 7,652 bytes, 9 lines download raw bytes

1import{j as e,r as I,am as $,an as z,X as L,ao as T,v as q,ap as A}from"./vendor-ui-NH_ejEPi.js";import{h as M,c as O,r as d}from"./vendor-react-BaFKGkTN.js";import{l as N,m as B,T as w,t as W,u as X,p as _,M as C,N as k,O as D}from"./vendor-firebase-lOQEsijG.js";import{d as p,s as S}from"./index-BB7qmMf9.js";const c=n=>n.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"");function Q(){const{id:n}=M(),g=O(),[x,u]=d.useState(!1),[b,f]=d.useState(!1),[h,j]=d.useState(!1),[a,r]=d.useState({title:"",slug:"",excerpt:"",content:"",image:"",published:!0}),m=!n;d.useEffect(()=>{m||U()},[n]);const U=async()=>{u(!0);try{const s=N(p,"posts",n),l=await B(s);if(l.exists()){const t=l.data();r({title:t.title||"",slug:t.slug||c(t.title||""),excerpt:t.excerpt||"",content:t.content||"",image:t.image||"",published:t.published??!0})}}catch(s){console.error("Error fetching post:",s)}finally{u(!1)}},R=async s=>{const l=s.target.files?.[0];if(l){f(!0);try{const t=C(S,`blog-images/${Date.now()}-${l.name}`);await k(t,l);const i=await D(t);r(o=>({...o,image:i}))}catch(t){console.error("Error uploading image:",t),alert("Failed to upload image.")}finally{f(!1)}}},E=async s=>{const l=s.target.files;if(!(!l||l.length===0)){j(!0);try{const t=Date.now();let i="";for(const o of Array.from(l)){const y=C(S,`blog-resources/${t}/${o.name}`);await k(y,o);const v=await D(y),F=o.type.startsWith("image/");i+=F?`
2
3![${o.name}](${v})
4
5`:`
6
7[Download ${o.name}](${v})
8
9`}r(o=>({...o,content:o.content+i})),s.target.value=""}catch(t){console.error("Error uploading resource:",t),alert("Failed to upload resource.")}finally{j(!1)}}},P=async s=>{s.preventDefault(),u(!0);const l=a.slug?c(a.slug):c(a.title),t={...a,slug:l,isMarkdown:!0,date:new Date().toISOString().split("T")[0],updatedAt:w.now()};try{m?await W(X(p,"posts"),{...t,createdAt:w.now()}):await _(N(p,"posts",n),t,{merge:!0}),g("/admin/blogs")}catch(i){console.error("Error saving post:",i),alert("Failed to save post")}finally{u(!1)}};return e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("button",{onClick:()=>g("/admin/blogs"),className:"p-2 hover:bg-slate-200 rounded-full transition-colors",children:e.jsx(I,{size:20,className:"text-slate-600"})}),e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:m?"Create New Post":"Edit Post"})]}),e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-slate-200 p-8",children:e.jsxs("form",{onSubmit:P,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Title"}),e.jsx("input",{type:"text",value:a.title,onChange:s=>{const l=s.target.value;r(t=>({...t,title:l,slug:!t.slug||t.slug===c(t.title)?c(l):t.slug}))},className:"w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-brand-blue focus:border-transparent outline-none",placeholder:"Enter post title",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"URL Slug"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-xs text-slate-500 bg-slate-100 px-3 py-2.5 border border-r-0 border-slate-300 rounded-l-lg select-none font-mono",children:"/blog/"}),e.jsx("input",{type:"text",value:a.slug,onChange:s=>r({...a,slug:c(s.target.value)}),className:"w-full px-4 py-2 border border-slate-300 rounded-r-lg focus:ring-2 focus:ring-brand-blue focus:border-transparent outline-none text-sm font-mono",placeholder:"clean-article-slug",required:!0})]}),e.jsxs("p",{className:"text-xs text-slate-400 mt-1",children:["Public URL: ",e.jsxs("span",{className:"text-slate-600 font-medium",children:["https://aspireinclusion.uk/blog/",a.slug||"clean-article-slug"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Excerpt"}),e.jsx("textarea",{value:a.excerpt,onChange:s=>r({...a,excerpt:s.target.value}),className:"w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-brand-blue focus:border-transparent outline-none h-20 resize-none",placeholder:"Brief summary for the card view...",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Cover Image"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-4 items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx($,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",size:18}),e.jsx("input",{type:"text",value:a.image,onChange:s=>r({...a,image:s.target.value}),className:"w-full pl-10 pr-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-brand-blue focus:border-transparent outline-none",placeholder:"Or enter image URL manually..."})]}),e.jsx("span",{className:"text-sm text-slate-500",children:"OR"}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"file-upload",className:"cursor-pointer bg-slate-100 px-4 py-2 rounded-lg text-slate-700 font-medium hover:bg-slate-200 transition-colors flex items-center gap-2",children:[e.jsx(z,{size:18}),b?"Uploading...":"Upload Image"]}),e.jsx("input",{id:"file-upload",type:"file",accept:"image/*",className:"hidden",onChange:R,disabled:b})]})]}),a.image&&e.jsxs("div",{className:"relative group w-full h-48 rounded-lg overflow-hidden border border-slate-200 bg-slate-50",children:[e.jsx("img",{src:a.image,alt:"Preview",className:"w-full h-full object-cover"}),e.jsx("button",{type:"button",onClick:()=>r({...a,image:""}),className:"absolute top-2 right-2 bg-white/90 p-1 rounded-full text-slate-600 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:e.jsx(L,{size:16})})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700",children:"Content (Markdown supp
9orted)"}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"resource-upload",className:"cursor-pointer text-sm bg-slate-100 px-3 py-1.5 rounded-lg text-brand-blue font-medium hover:bg-slate-200 transition-colors flex items-center gap-2",children:[e.jsx(T,{size:16}),h?"Uploading...":"Insert Image or PDF"]}),e.jsx("input",{id:"resource-upload",type:"file",accept:"image/*,.pdf,.doc,.docx",multiple:!0,className:"hidden",onChange:E,disabled:h})]})]}),e.jsx("textarea",{value:a.content,onChange:s=>r({...a,content:s.target.value}),className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-brand-blue focus:border-transparent outline-none h-96 font-mono text-sm leading-relaxed",placeholder:"Write your article here... Markdown is supported! Use **bold** for bold text, etc.",required:!0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"published",checked:a.published,onChange:s=>r({...a,published:s.target.checked}),className:"w-4 h-4 text-brand-blue rounded focus:ring-brand-blue"}),e.jsx("label",{htmlFor:"published",className:"text-sm font-medium text-slate-700",children:"Publish immediately"})]}),e.jsx("div",{className:"flex justify-end pt-6 border-t border-slate-100",children:e.jsx("button",{type:"submit",disabled:x,className:"bg-brand-blue text-white px-8 py-3 rounded-lg font-semibold hover:bg-blue-600 transition-colors flex items-center gap-2 disabled:opacity-70",children:x?e.jsx(q,{className:"animate-spin",size:20}):e.jsxs(e.Fragment,{children:[e.jsx(A,{size:20})," Save Post"]})})})]})})]})}export{Q as BlogEditor};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.