import { SITE_INTRO, SITE_TITLE, fetchIndexDocs, renderIndexSections, type IndexDoc } from '@/lib/llms' import { freeEarlyAccess } from '@/lib/launch' import { formatDate } from '@/lib/format' import { lexicalToPlain } from '@/lib/lexical' export const dynamic = 'force-dynamic' export async function GET(): Promise { const early = freeEarlyAccess() // Public read path: the content field's read ACL already decides body // availability — with early access every published body passes; with billing // on, VIP bodies come back undefined and are listed members-only. const docs = await fetchIndexDocs(true) as (IndexDoc & { content?: unknown })[] const parts: string[] = [ `# ${SITE_TITLE}`, '', `> ${SITE_INTRO}`, '', renderIndexSections(docs, !early), '---', '', '# الأدلة الكاملة', '', ] for (const doc of docs) { const vipOnly = !early && doc.access === 'vip' const suffix = vipOnly ? ' (دليل للأعضاء)' : '' parts.push(`## ${doc.title}${suffix}`, '') parts.push(`URL: /posts/${doc.slug}`, '') if (doc.dek) parts.push(doc.dek, '') if (doc.updatedAt && doc.publishedAt && doc.updatedAt !== doc.publishedAt) { parts.push(`حُدّث: ${formatDate(doc.updatedAt)}`, '') } if (vipOnly) { parts.push('هذا الدليل متاح للأعضاء فقط. العضوية: /subscription', '') } else if (typeof doc.content === 'object' && doc.content !== null) { parts.push(lexicalToPlain(doc.content), '') } parts.push('---', '') } return new Response(parts.join('\n'), { headers: { 'content-type': 'text/plain; charset=utf-8' } }) }