File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import { notFound } from 'next/navigation'
2+ import { type NextRequest , NextResponse } from 'next/server'
3+ import { getLLMText } from '@/lib/llms'
4+ import { source } from '@/lib/source'
5+
6+ export const revalidate = false
7+
8+ export async function GET ( _req : NextRequest , { params } : { params : Promise < { slug ?: string [ ] } > } ) {
9+ const { slug } = await params
10+ const page = source . getPage ( slug )
11+ if ( ! page ) notFound ( )
12+
13+ return new NextResponse ( await getLLMText ( page ) )
14+ }
15+
16+ export function generateStaticParams ( ) {
17+ return source . generateParams ( )
18+ }
Original file line number Diff line number Diff line change 1+ import { getLLMText } from '@/lib/llms'
2+ import { source } from '@/lib/source'
3+
4+ // cached forever
5+ export const revalidate = false
6+
7+ export async function GET ( ) {
8+ const scan = source . getPages ( ) . map ( getLLMText )
9+ const scanned = await Promise . all ( scan )
10+
11+ return new Response ( scanned . join ( '\n\n' ) )
12+ }
Original file line number Diff line number Diff line change 1+ import type { InferPageType } from 'fumadocs-core/source'
2+ import { remarkInclude } from 'fumadocs-mdx/config'
3+ import { remark } from 'remark'
4+ import remarkGfm from 'remark-gfm'
5+ import remarkMdx from 'remark-mdx'
6+ import type { source } from '@/lib/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+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ const config = {
1212 destination : '/introduction' ,
1313 permanent : true ,
1414 } ,
15+ {
16+ source : '/docs/:path*.mdx' ,
17+ destination : '/llms.mdx/:path*' ,
18+ permanent : true ,
19+ } ,
1520 ]
1621 } ,
1722}
You can’t perform that action at this time.
0 commit comments