@@ -408,6 +408,23 @@ const prepareMarkdown = async ({
408408const LLMS_TXT = "llms.txt" ;
409409const LLMS_TXT_FULL = "llms-full.txt" ;
410410
411+ const resolveMarkdown = ( {
412+ dataRoutes,
413+ path
414+ } : {
415+ dataRoutes : RoutesData ;
416+ path : string ;
417+ } ) : RouteData | undefined => {
418+ const data = dataRoutes . get ( path ) ;
419+
420+ if ( data !== undefined ) {
421+ return data ;
422+ }
423+
424+ // root dir is indexed with a trailing slash
425+ return dataRoutes . get ( `${ path } /` ) ;
426+ } ;
427+
411428const generateLlmsTxt = async ( {
412429 groupedRoutes,
413430 dataRoutes,
@@ -426,7 +443,7 @@ const generateLlmsTxt = async ({
426443 path,
427444 title : customTitle
428445 } : GroupedRouteChild ) : string | undefined => {
429- const data = dataRoutes . get ( path ) ;
446+ const data = resolveMarkdown ( { dataRoutes , path } ) ;
430447
431448 if ( data === undefined ) {
432449 return undefined ;
@@ -456,6 +473,7 @@ const generateLlmsTxt = async ({
456473 . map (
457474 ( [ key , { children, title } ] ) => `${ buildTitle ( { key, title } ) }
458475
476+ ${ buildLink ( { path : key , title } ) }
459477${ children . map ( buildLink ) . join ( "\n" ) } `
460478 )
461479 . join ( "\n\n" ) ;
@@ -481,7 +499,7 @@ const generateLlmsTxtFull = async ({
481499} & Pick < LoadContext , "siteConfig" | "outDir" > &
482500 Pick < PluginOptions , "description" | "docsDir" > ) => {
483501 const buildMarkdown = ( { path } : GroupedRouteChild ) : string | undefined => {
484- const data = dataRoutes . get ( path ) ;
502+ const data = resolveMarkdown ( { dataRoutes , path } ) ;
485503
486504 if ( data === undefined ) {
487505 return undefined ;
@@ -495,7 +513,13 @@ const generateLlmsTxtFull = async ({
495513 } ;
496514
497515 const content = groupedRoutes
498- . map ( ( [ _ , { children } ] ) => children . map ( buildMarkdown ) . join ( "\n\n" ) )
516+ . map (
517+ ( [
518+ key ,
519+ { children, title }
520+ ] ) => `${ buildMarkdown ( { path : key , title } ) } \n\n
521+ ${ children . map ( buildMarkdown ) . join ( "\n\n" ) } `
522+ )
499523 . join ( "\n\n" ) ;
500524
501525 await generateLlmsTxtFile ( {
0 commit comments