Skip to content

Commit faf0e11

Browse files
feat: handle undefined
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent 3889bc3 commit faf0e11

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

plugins/docusaurus.llms.plugin.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,16 @@ const generateLlmsTxt = async ({
470470
};
471471

472472
const content = groupedRoutes
473-
.map(
474-
([key, { children, title }]) => `${buildTitle({ key, title })}
473+
.map(([key, { children, title }]) => {
474+
const rootLink = buildLink({ path: key, title });
475+
476+
return `${buildTitle({ key, title })}
475477
476-
${buildLink({ path: key, title })}
477-
${children.map(buildLink).join("\n")}`
478-
)
478+
${rootLink !== undefined ? `${rootLink}\n` : ""}${children
479+
.map(buildLink)
480+
.filter((l) => l !== undefined)
481+
.join("\n")}`;
482+
})
479483
.join("\n\n");
480484

481485
await generateLlmsTxtFile({
@@ -513,10 +517,14 @@ const generateLlmsTxtFull = async ({
513517
};
514518

515519
const content = groupedRoutes
516-
.map(
517-
([key, { children, title }]) => `${buildMarkdown({ path: key, title })}
518-
${children.map(buildMarkdown).join("\n\n")}`
519-
)
520+
.map(([key, { children, title }]) => {
521+
const rootMarkdown = buildMarkdown({ path: key, title });
522+
523+
return `${rootMarkdown !== undefined ? `${rootMarkdown}\n\n` : ""}${children
524+
.map(buildMarkdown)
525+
.filter((m) => m !== undefined)
526+
.join("\n\n")}`;
527+
})
520528
.join("\n\n");
521529

522530
await generateLlmsTxtFile({

0 commit comments

Comments
 (0)