@@ -10,51 +10,22 @@ import remarkMdx from "remark-mdx";
1010
1111const processor = remark ( ) . use ( remarkMdx ) . use ( remarkInclude ) . use ( remarkGfm ) ;
1212
13- export async function getLLMText ( page : Page ) {
14- // eslint-disable-next-line no-console
15- console . error ( "🔥 getLLMText EXECUTED at" , new Date ( ) . toISOString ( ) ) ;
16-
17- // Resolve a readable MDX path in this Lambda:
18- // 1) app-relative (when Vercel Root Directory is apps/developer-hub)
19- // 2) repo-relative (monorepo root)
20- // 3) absolutePath provided by Fumadocs (works locally)
21- const pathArray : string [ ] = Array . isArray ( page . path )
22- ? page . path
23- : [ page . path ] ;
24- const appRelTry = path . join ( process . cwd ( ) , "content" , "docs" , ...pathArray ) ;
25- const repoRelTry = path . join (
26- process . cwd ( ) ,
27- "apps" ,
28- "developer-hub" ,
29- "content" ,
30- "docs" ,
31- ...pathArray ,
32- ) ;
33- const absTry = page . absolutePath ;
13+ function resolveMdxPath ( page : Page ) : string {
14+ const parts : string [ ] = Array . isArray ( page . path ) ? page . path : [ page . path ] ;
3415
35- let mdxPath : string | undefined ;
36- if ( existsSync ( appRelTry ) ) {
37- mdxPath = appRelTry ;
38- } else if ( existsSync ( repoRelTry ) ) {
39- mdxPath = repoRelTry ;
40- } else if ( absTry && existsSync ( absTry ) ) {
41- mdxPath = absTry ;
42- }
16+ const appRelPath = [ process . cwd ( ) , "content" , "docs" , ...parts ] as [
17+ string ,
18+ ...string [ ] ,
19+ ] ;
4320
44- // eslint-disable-next-line no-console
45- console . error ( "🧪[LLM] chosenPath=" , mdxPath ) ;
21+ if ( existsSync ( path . join ( ...appRelPath ) ) ) {
22+ return path . join ( ...appRelPath ) ;
23+ } else throw new Error ( `MDX file not found at ${ path . join ( ...appRelPath ) } ` ) ;
24+ }
4625
47- if ( ! mdxPath ) {
48- throw new Error (
49- `MDX file not found at any known path:
50- appRel=${ appRelTry } ,
51- repoRel=${ repoRelTry } ,
52- abs=${ absTry } ` ,
53- ) ;
54- }
26+ export async function getLLMText ( page : Page ) {
27+ const mdxPath = resolveMdxPath ( page ) ;
5528
56- // eslint-disable-next-line no-console
57- console . error ( `Getting LLM text for ${ mdxPath } ` ) ;
5829 const processed = await processor . process ( {
5930 path : mdxPath ,
6031 value : await readFile ( mdxPath , "utf8" ) ,
0 commit comments