feat(llms): add LLM text processing and routing for MDX and TXT files (#470)

This commit is contained in:
Aditya Tripathi
2025-06-10 21:02:37 +05:30
committed by GitHub
parent 726901cb31
commit aa2577be91
4 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import { notFound } from 'next/navigation'
import { type NextRequest, NextResponse } from 'next/server'
import { getLLMText } from '@/lib/llms'
import { source } from '@/lib/source'
export const revalidate = false
export async function GET(_req: NextRequest, { params }: { params: Promise<{ slug?: string[] }> }) {
const { slug } = await params
const page = source.getPage(slug)
if (!page) notFound()
return new NextResponse(await getLLMText(page))
}
export function generateStaticParams() {
return source.generateParams()
}

View File

@@ -0,0 +1,12 @@
import { getLLMText } from '@/lib/llms'
import { source } from '@/lib/source'
// cached forever
export const revalidate = false
export async function GET() {
const scan = source.getPages().map(getLLMText)
const scanned = await Promise.all(scan)
return new Response(scanned.join('\n\n'))
}

22
apps/docs/lib/llms.ts Normal file
View File

@@ -0,0 +1,22 @@
import type { InferPageType } from 'fumadocs-core/source'
import { remarkInclude } from 'fumadocs-mdx/config'
import { remark } from 'remark'
import remarkGfm from 'remark-gfm'
import remarkMdx from 'remark-mdx'
import type { source } from '@/lib/source'
const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm)
export async function getLLMText(page: InferPageType<typeof source>) {
const processed = await processor.process({
path: page.data._file.absolutePath,
value: page.data.content,
})
return `# ${page.data.title}
URL: ${page.url}
${page.data.description}
${processed.value}`
}

View File

@@ -12,6 +12,11 @@ const config = {
destination: '/introduction',
permanent: true,
},
{
source: '/docs/:path*.mdx',
destination: '/llms.mdx/:path*',
permanent: true,
},
]
},
}