File tree Expand file tree Collapse file tree 6 files changed +115
-0
lines changed
Expand file tree Collapse file tree 6 files changed +115
-0
lines changed 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 { apiSource , source } from './source' ;
7+
8+ const processor = remark ( )
9+ . use ( remarkMdx )
10+ // needed for Fumadocs MDX
11+ . use ( remarkInclude )
12+ . use ( remarkGfm ) ;
13+
14+ export async function getLLMText ( page : InferPageType < typeof source > | InferPageType < typeof apiSource > ) {
15+ // Remove the Fumadocs generated comment before processing
16+ let content = page . data . content ;
17+
18+ // Remove the specific Fumadocs comment that appears in generated API docs
19+ content = content . replace (
20+ / \{ \s * \/ \* \s * T h i s f i l e w a s g e n e r a t e d b y F u m a d o c s \. D o n o t e d i t t h i s f i l e d i r e c t l y \. A n y c h a n g e s s h o u l d b e m a d e b y r u n n i n g t h e g e n e r a t i o n c o m m a n d a g a i n \. \s * \* \/ \s * \} / g,
21+ ''
22+ ) ;
23+
24+ const processed = await processor . process ( {
25+ path : page . data . _file . absolutePath ,
26+ value : content ,
27+ } ) ;
28+
29+ return `# ${ page . data . title }
30+ URL: ${ page . url }
31+ Source: ${ page . data . _file . absolutePath }
32+
33+ ${ page . data . description || '' }
34+
35+ ${ processed . value } `;
36+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,15 @@ const config = {
2626 } ,
2727 async rewrites ( ) {
2828 return [
29+ // Redirect .mdx requests to the llms.mdx route handler
30+ {
31+ source : '/docs/:path*.mdx' ,
32+ destination : '/llms.mdx/:path*' ,
33+ } ,
34+ {
35+ source : '/api/:path*.mdx' ,
36+ destination : '/llms.mdx/:path*' ,
37+ } ,
2938 // Serve OpenAPI files from the openapi directory
3039 {
3140 source : '/openapi/:path*' ,
Original file line number Diff line number Diff line change 4141 "react" : " ^18.3.1" ,
4242 "react-dom" : " ^18.3.1" ,
4343 "react-remove-scroll" : " ^2.7.0" ,
44+ "remark" : " ^15.0.1" ,
45+ "remark-gfm" : " ^4.0.1" ,
46+ "remark-mdx" : " ^3.1.0" ,
4447 "shiki" : " ^3.4.2" ,
4548 "tailwind-merge" : " ^3.3.0"
4649 },
Original file line number Diff line number Diff line change 1+ import { getLLMText } from 'lib/get-llm-text' ;
2+ import { apiSource , source } from 'lib/source' ;
3+ import { notFound } from 'next/navigation' ;
4+ import { type NextRequest , NextResponse } from 'next/server' ;
5+
6+ export const revalidate = false ;
7+
8+ export async function GET (
9+ _req : NextRequest ,
10+ { params } : { params : Promise < { slug ?: string [ ] } > } ,
11+ ) {
12+ const { slug } = await params ;
13+
14+ // Try to find the page in either source
15+ let page = source . getPage ( slug ) ;
16+
17+ // If not found in main docs, try API docs
18+ if ( ! page ) {
19+ page = apiSource . getPage ( slug ) ;
20+ }
21+
22+ if ( ! page ) notFound ( ) ;
23+
24+ return new NextResponse ( await getLLMText ( page ) ) ;
25+ }
26+
27+ export function generateStaticParams ( ) {
28+ // Generate static params for both main docs and API docs
29+ const docsParams = source . generateParams ( ) ;
30+ const apiParams = apiSource . generateParams ( ) ;
31+
32+ return [ ...docsParams , ...apiParams ] ;
33+ }
Original file line number Diff line number Diff line change 1+ import { getLLMText } from 'lib/get-llm-text' ;
2+ import { apiSource , source } from 'lib/source' ;
3+
4+ // cached forever
5+ export const revalidate = false ;
6+
7+ export async function GET ( ) {
8+ // Get all pages from both main docs and API docs
9+ const docsPages = source . getPages ( ) ;
10+ const apiPages = apiSource . getPages ( ) ;
11+
12+ // Process all pages
13+ const docsPromises = docsPages . map ( getLLMText ) ;
14+ const apiPromises = apiPages . map ( getLLMText ) ;
15+
16+ const [ docsContent , apiContent ] = await Promise . all ( [
17+ Promise . all ( docsPromises ) ,
18+ Promise . all ( apiPromises )
19+ ] ) ;
20+
21+ // Combine all content
22+ const allContent = [ ...docsContent , ...apiContent ] ;
23+
24+ return new Response ( allContent . join ( '\n\n' ) ) ;
25+ }
You can’t perform that action at this time.
0 commit comments