Skip to content

Commit 7f54515

Browse files
committed
feat: add LLM text processing and route for retrieving formatted content
1 parent d94ae6e commit 7f54515

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/app/llms.txt/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { source } from "@/lib/source"
2+
import { getLLMText } from "@/lib/get-llm-text"
3+
4+
export const revalidate = false
5+
6+
export async function GET() {
7+
const scan = source.getPages().map(getLLMText)
8+
const scanned = await Promise.all(scan)
9+
10+
return new Response(scanned.join("\n\n"))
11+
}

src/lib/get-llm-text.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { remark } from "remark"
2+
import remarkGfm from "remark-gfm"
3+
import remarkMdx from "remark-mdx"
4+
import { remarkInclude } from "fumadocs-mdx/config"
5+
import { source } from "@/lib/source"
6+
import type { InferPageType } from "fumadocs-core/source"
7+
8+
const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm)
9+
10+
export async function getLLMText(page: InferPageType<typeof source>) {
11+
const processed = await processor.process({
12+
path: page.data._file.absolutePath,
13+
value: page.data.content,
14+
})
15+
16+
return `# ${page.data.title}
17+
URL: ${page.url}
18+
19+
${page.data.description}
20+
21+
${processed.value}`
22+
}

0 commit comments

Comments
 (0)