diff --git a/docs/app/llms-full.txt/route.ts b/docs/app/llms-full.txt/route.ts new file mode 100644 index 000000000..fb3537a35 --- /dev/null +++ b/docs/app/llms-full.txt/route.ts @@ -0,0 +1,14 @@ +import { source } from '@/lib/source'; +import { getLLMText } from '@/lib/get-llm-text'; + +export const revalidate = false; + +export async function GET() { + const pages = source.getPages(); + const scanned = await Promise.all(pages.map(getLLMText)); + return new Response(scanned.join('\n\n'), { + headers: { + 'Content-Type': 'text/markdown', + }, + }); +} diff --git a/docs/app/llms.txt/route.ts b/docs/app/llms.txt/route.ts new file mode 100644 index 000000000..f4bfc3178 --- /dev/null +++ b/docs/app/llms.txt/route.ts @@ -0,0 +1,27 @@ +import { source } from '@/lib/source'; + +export const revalidate = false; + +export function GET() { + const pages = source.getPages(); + const lines: string[] = []; + + for (const page of pages) { + const url = page.url; + const data = page.data as { title?: string; description?: string }; + const title = data.title ?? 'Page'; + const description = data.description ?? ''; + lines.push(`## ${title}`); + if (description) { + lines.push(`> ${description}`); + } + lines.push(`- Source: ${url}\n`); + } + + const result = lines.join('\n'); + return new Response(result || '# No pages found', { + headers: { + 'Content-Type': 'text/markdown', + }, + }); +} diff --git a/docs/lib/get-llm-text.ts b/docs/lib/get-llm-text.ts new file mode 100644 index 000000000..1b87de7f9 --- /dev/null +++ b/docs/lib/get-llm-text.ts @@ -0,0 +1,9 @@ +import { source } from '@/lib/source'; +import type { InferPageType } from 'fumadocs-core/source'; + +type Page = InferPageType; + +export async function getLLMText(page: Page): Promise { + const processed = await page.data.getText?.('processed'); + return processed ?? ''; +} diff --git a/docs/source.config.ts b/docs/source.config.ts index 0b00e442c..47bb43d0a 100644 --- a/docs/source.config.ts +++ b/docs/source.config.ts @@ -3,6 +3,11 @@ import lastModified from 'fumadocs-mdx/plugins/last-modified'; export const docs = defineDocs({ dir: 'content/docs', + docs: { + postprocess: { + includeProcessedMarkdown: true, + }, + }, }); export default defineConfig({