@@ -163,6 +163,24 @@ function removeReferences(content: string): string {
163163
164164const AllImports : Array < { name : string ; module : string } > = [ ] ;
165165
166+ const fdiReference = JSON . parse ( fs . readFileSync ( "./static/fdi.json" , "utf8" ) ) as OpenAPIV3 . Document ;
167+ const cdiReference = JSON . parse ( fs . readFileSync ( "./static/cdi.json" , "utf8" ) ) as OpenAPIV3 . Document ;
168+
169+ async function parseApiReferenceContent ( filePath : string , apiType : "fdi" | "cdi" ) : Promise < string > {
170+ const mdxContent = await fs . promises . readFile ( filePath , "utf8" ) ;
171+ const regex = / p a t h \s * = \s * " ( [ ^ " ] + ) " / ;
172+ const match = mdxContent . match ( regex ) ;
173+ const path = match [ 1 ] ;
174+ const apiSpec = apiType === "fdi" ? fdiReference : cdiReference ;
175+
176+ if ( path ) {
177+ const value = apiSpec . paths [ path ] ;
178+ if ( value ) return JSON . stringify ( value , null , 2 ) ;
179+ }
180+
181+ return "" ;
182+ }
183+
166184async function parseMdxContent ( filePath : string , usePageTitle = false ) : Promise < string > {
167185 const mdxContent = await fs . promises . readFile ( filePath , "utf8" ) ;
168186 const { content } = matter ( mdxContent ) ;
@@ -290,7 +308,7 @@ function buildTitle(currentTitle: string, filePath: string): string {
290308}
291309
292310async function generateApiReferenceText ( apiName : "cdi" | "fdi" ) {
293- const apiReference = JSON . parse ( await fs . promises . readFile ( `./static/ ${ apiName } .json` , "utf8" ) ) as OpenAPIV3 . Document ;
311+ const apiReference = apiName === "fdi" ? fdiReference : cdiReference ;
294312 const apiReferenceMapping = JSON . parse (
295313 await fs . promises . readFile ( `./static/${ apiName } -mapping.json` , "utf8" ) ,
296314 ) as OpenAPIV3 . Document ;
@@ -319,14 +337,14 @@ export default function createLLMFullFile(context) {
319337 const contentDir = path . join ( siteDir , "docs" ) ;
320338 const allFiles : { title : string ; content : string ; path : string ; description : string } [ ] = [ ] ;
321339
322- const skipFiles = [
323- "docs/index.mdx" ,
324- "docs/quickstart/example-apps/generate-example-app.mdx" ,
325- "docs/quickstart/next-steps.mdx" ,
326- "overview.mdx" ,
327- "introduction.mdx" ,
328- "compatibility-table.mdx" ,
329- ] ;
340+ // const skipFiles = [
341+ // "docs/index.mdx",
342+ // "docs/quickstart/example-apps/generate-example-app.mdx",
343+ // "docs/quickstart/next-steps.mdx",
344+ // "overview.mdx",
345+ // "introduction.mdx",
346+ // "compatibility-table.mdx",
347+ // ];
330348
331349 const mainDirectories = [
332350 "/quickstart" ,
@@ -341,20 +359,22 @@ export default function createLLMFullFile(context) {
341359
342360 for ( const dir of mainDirectories ) {
343361 const fullPath = path . join ( contentDir , dir ) ;
344- const mdxFiles = await getAllMdxFiles ( fullPath , skipFiles ) ;
362+ // const mdxFiles = await getAllMdxFiles(fullPath, skipFiles);
363+ const mdxFiles = await getAllMdxFiles ( fullPath , [ ] ) ;
345364 allFiles . push ( ...mdxFiles ) ;
346365 }
347366
348- const filesWithoutReferences = allFiles . filter (
349- ( file ) => ! file . path . includes ( "cdi" ) && ! file . path . includes ( "fdi" ) ,
350- ) ;
351-
352- return { files : filesWithoutReferences } ;
367+ return { files : allFiles } ;
353368 } ,
354369 postBuild : async ( { content, outDir, routes } ) => {
355370 const parsedFiles = await Promise . all (
356371 content . files . map ( async ( file ) => {
357- const content = await parseMdxContent ( file . path ) ;
372+ let content = "" ;
373+ if ( ( file . path . includes ( "fdi" ) || file . path . includes ( "cdi" ) ) && ! file . path . includes ( "introduction" ) ) {
374+ content = await parseApiReferenceContent ( file . path , file . path . includes ( "fdi" ) ? "fdi" : "cdi" ) ;
375+ } else {
376+ content = await parseMdxContent ( file . path ) ;
377+ }
358378 return { ...file , content } ;
359379 } ) ,
360380 ) ;
0 commit comments