1import{j as e,u as I}from"./query-_koPiPsI.js";import{r as b,L as j}from"./react-vendor-h1rQ_Bae.js";import{ay as M,az as D,aA as O,s as v,aB as L,U as _,aC as z,C as k,N as F,aD as T,z as P,J as B,I as G}from"./index-Dq2zLArw.js";import{A as H,a as J,b as R}from"./avatar-BmlbLwKw.js";import{f as K}from"./usePublicPostViews-9lUkjDPs.js";import{E as W}from"./eye-DeaWVGHm.js";import"./ui-radix-CKwvnS8F.js";import"./supabase-DL6nu9mS.js";import"./charts-Xu79y1bN.js";import"./motion-nVmI7L5T.js";import"./index-CnMJwqSh.js";const Q=({articles:u,title:h="Published Articles",description:w="All published insights and stories from ThoughtForge creators",url:m})=>{const x=D(),o=m||`${x}/read`,y={"@context":"https://schema.org","@type":"CollectionPage",name:h,description:w,url:o,publisher:{"@type":"Organization",name:"ThoughtForge",url:x,logo:{"@type":"ImageObject",url:`${x}/logo.png`}},mainEntity:{"@type":"ItemList",numberOfItems:u.length,itemListElement:u.slice(0,50).map((i,f)=>{const c=i.profiles?.username,N=c?`${x}/user/${c}/${i.slug}`:`${x}/read/${i.slug}`;return{"@type":"ListItem",position:f+1,item:{"@type":"Article",name:i.title,url:N,...i.excerpt&&{description:i.excerpt},...i.featured_image_url&&{image:i.featured_image_url},...i.platform_published_at&&{datePublished:i.platform_published_at},...i.profiles?.full_name&&{author:{"@type":"Person",name:i.profiles.full_name,...c&&{url:`${x}/user/${c}`}}}}}})}};return e.jsx(M,{children:e.jsx("script",{type:"application/ld+json",children:JSON.stringify(y)})})};function ne(){const{domainInfo:u}=O(),[h,w]=b.useState(""),[m,x]=b.useState(null),{data:o,isLoading:y}=I({queryKey:["published-posts",u?.userId],queryFn:async()=>{let t=v.from("posts").select("*").eq("status","published").eq("published_to_platform",!0);u?.userId?t=t.eq("author_id",u.userId).in("visibility",["both","whitelabel"]):t=t.in("visibility",["both","platform"]);const{data:s,error:l}=await t.order("platform_published_at",{ascending:!1});if(l)throw l;const a=Array.from(new Set((s||[]).map(r=>r.author_id).filter(Boolean)));let d=new Map;if(a.length){const{data:r}=await v.from("public_profiles").select("id, full_name, avatar_url, username").in("id",a);d=new Map((r||[]).map(p=>[p.id,p]))}return(s||[]).map(r=>({...r,profiles:d.get(r.author_id)??null}))},enabled:!!u}),{data:i}=I({queryKey:["read-view-counts",o?.map(t=>t.id).join(",")],enabled:!!o?.length,staleTime:5*60*1e3,queryFn:async()=>{const t=new Map;for(const a of o||[]){if(!a.author_id)continue;const d=a.profiles?.username||"";t.has(a.author_id)||t.set(a.author_id,{username:d})}const s=await Promise.all(Array.from(t.entries()).map(async([a,{username:d}])=>{const{data:r}=await v.rpc("get_post_view_counts",{p_user_id:a,p_username:d});return r||[]})),l={};for(const a of s)for(const d of a)l[d.post_id]=Number(d.view_count);return l}}),f=b.useMemo(()=>{const t=new Map;for(const s of o||[]){const l=(s.seo_keyword||"").trim();l&&t.set(l,(t.get(l)||0)+1)}return Array.from(t.entries()).sort((s,l)=>l[1]-s[1]).slice(0,6).map(([s])=>s)},[o]),c=b.useMemo(()=>{if(!o?.length)return o;const t=h.trim().toLowerCase();return o.filter(s=>{if(m&&(s.seo_keyword||"").trim()!==m)return!1;if(!t)return!0;const l=(s.title||"").toLowerCase(),a=(s.excerpt||"").toLowerCase(),d=(s.profiles?.full_name||s.profiles?.username||"").toLowerCase(),r=(s.seo_keyword||"").toLowerCase();return l.includes(t)||a.includes(t)||d.includes(t)||r.includes(t)})},[o,h,m]);if(y)return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(L,{}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 pt-24 pb-16",children:[e.jsxs("div",{className:"text-center mb-12",children:[e.jsx(_,{className:"h-12 w-64 mx-auto mb-4"}),e.jsx(_,{className:"h-6 w-96 mx-auto"})]}),e.jsx("div",{className:"grid md:grid-cols-3 gap-8",children:[1,2,3,4,5,6].map(t=>e.jsx(_,{className:"h-96"},t))})]})]});const N=o?.map(t=>({id:t.id,title:t.title,slug:t.slug,excerpt:t.excerpt,featured_image_url:t.featured_image_url,platform_published_at:t.platform_published_at,profiles:t.profiles}))||[],g=u?.type==="whitelabel",A=!h&&!m&&(c?.length??0)>=3,n=A?c[0]:null,U=(A?c.slice(1):c)||[],C=n?.profiles?.username,$=n?g?`/${n.slug}`:C?`/user/${C}/${n.slug}`:null:null;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(z,{title:g?"Articles":"Blog | ThoughtForge",description:"Field notes on AI search, answer engines and findability â how to get ranked by Google and cited by ChatGPT, Perplexity, Claude and Gemini."}),e.jsx(Q,{articles:N}),e.jsx(L,{}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 pt-24 pb-16",children:[e.jsxs("div",{className:"text-center mb-10 animate-fade-in",children:[e.jsx("h1",{className:"text-3xl sm:text-4xl md:text-5xl font-bold mb-4",children:g?"Articles":"Blog"}),e.jsx("p",{className:"text-lg sm:text-xl text-muted-foreground font-light max-w-2xl mx-auto",children:g?"Everything published here, newest first.":"Field notes on AI search, answer engines and findability â written in the open while we build ThoughtForge."})]}),n&&$&&e.jsx(j,{to:$,className:"block group mb-12 animate-fade-in",children:e.jsx(k,{className:"overflow-hidden border-border/60 hover:shadow-glow transition-all duration-300",children:e.jsxs("div",{className:"grid md:grid-cols-2",children:[n.featured_image_url?e.jsx("div",{className:"relative h-56 md:h-full overflow-hidden",children:e.jsx("img",{src:n.featured_image_url,alt:n.title,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500",loading:"lazy"})}):e.jsx("div",{className:"hidden md:block bg-muted/30"}),e.jsxs("div",{className:"p-6 sm:p-10 flex flex-col justify-center",children:[e.jsx("span",{className:"text-xs uppercase tracking-widest text-primary mb-3",children:"Latest"}),e.jsx("h2",{className:"text-2xl sm:text-3xl font-semibold mb-3 group-hover:text-primary transition-colors",children:n.title}),n.excerpt&&e.jsx("p",{className:"text-muted-foreground leading-relaxed line-clamp-3",children:n.excerpt}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground mt-5",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"w-3 h-3"}),T(n.content||"")," min"]}),n.platform_published_at&&e.jsx("span",{children:P(new Date(n.platform_published_at),{addSuffix:!0})})]})]})]})})}),(o?.length??0)>0&&e.jsxs("div",{className:"mb-10 flex flex-col lg:flex-row lg:items-center gap-4 justify-between",children:[f.length>1?e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>x(null),className:`rounded-full border px-3 py-1.5 text-xs transition-colors ${m===null?"border-primary bg-primary/10 text-primary":"border-border text-muted-foreground hover:text-foreground"}`,children:"All"}),f.map(t=>e.jsx("button",{type:"button",onClick:()=>x(m===t?null:t),className:`rounded-full border px-3 py-1.5 text-xs transition-colors ${m===t?"border-primary bg-primary/10 text-primary":"border-border text-muted-foreground hover:text-foreground"}`,children:t},t))]}):e.jsx("div",{}),e.jsxs("div",{className:"relative w-full lg:w-72",children:[e.jsx(B,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(G,{type:"search",placeholder:"Search articlesâ¦",value:h,onChange:t=>w(t.target.value),className:"pl-9","aria-label":"Search articles"})]})]}),(h||m)&&e.jsxs("p",{className:"text-xs text-muted-foreground mb-6",children:[c?.length??0," result",(c?.length??0)===1?"":"s"]}),e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-6 sm:gap-8",children:[U?.map((t,s)=>{const l=T(t.content||""),a=u?.type==="whitelabel",d=u?.type==="platform",r=t.profiles?.username,p=t.profiles?.full_name,q=t.profiles?.avatar_url;if(!a&&!r)return console.warn("[read] missing username for post, skipping",{postId:t.id,slug:t.slug}),null;const E=a?`/${t.slug}`:`/user/${r}/${t.slug}`,S=i?.[t.id]??0;return e.jsx(j,{to:E,className:"block group animate-fade-in",style:{animationDelay:`${s*50}ms`},children:e.jsxs(k,{className:"h-full overflow-hidden hover:shadow-glow transition-all duration-300 hover:-translate-y-2",children:[t.featured_image_url&&e.jsxs("div",{className:"relative h-48 overflow-hidden",children:[e.jsx("img",{src:t.featured_image_url,alt:t.title,className:"w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-background/80 to-transparent"})]}),e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 group-hover:text-primary transition-colors line-clamp-2",children:t.title}),t.excerpt&&e.jsx("p",{className:"text-muted-foreground mb-4 line-clamp-3 text-sm",children:t.excerpt}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"w-3 h-3"}),l," min"]}),S>=1&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(W,{className:"w-3 h-3"}),K(S)]})]}),e.jsx("span",{children:P(new Date(t.platform_published_at),{addSuffix:!0})})]}),d&&(p||r)&&e.jsxs("div",{className:"flex items-center gap-2 mt-4 pt-4 border-t border-border/50",children:[e.jsxs(H,{
1className:"h-6 w-6",children:[e.jsx(J,{src:q,alt:p||r}),e.jsx(R,{className:"text-xs",children:(p||r||"?").charAt(0).toUpperCase()})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:p||`@${r}`})]})]})]})},t.id)}),!c?.length&&e.jsx("div",{className:"col-span-full",children:h||m?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-lg text-muted-foreground",children:"No articles match that filter"})}):e.jsxs(k,{className:"max-w-2xl mx-auto p-8 sm:p-10 text-center border-border/60",children:[e.jsx("h2",{className:"text-2xl sm:text-3xl font-semibold mb-3",children:"Nothing published here yet."}),e.jsx("p",{className:"text-muted-foreground mb-6 leading-relaxed",children:"This is where our field notes on AI search live â what we test, what works, and what doesn't. Nothing fake, nothing seeded; when it appears here, a human wrote it."}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[e.jsx(j,{to:"/auth?tab=signup",className:"inline-flex items-center justify-center rounded-md bg-primary text-primary-foreground px-5 py-2.5 text-sm font-medium hover:opacity-90 transition",children:"Start writing"}),e.jsx(j,{to:"/how-it-works",className:"inline-flex items-center justify-center rounded-md border border-border px-5 py-2.5 text-sm font-medium hover:bg-muted transition",children:"See how it works"})]})]})})]})]})]})}export{ne as default};
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.