diff --git a/scripts/src/generate-llms-txt.ts b/scripts/src/generate-llms-txt.ts index 73e160f6a35..2eb18ae16d3 100644 --- a/scripts/src/generate-llms-txt.ts +++ b/scripts/src/generate-llms-txt.ts @@ -36,6 +36,7 @@ const INPUT_FILE_PATHS = [ const SLUG_TO_URL = { 'architecture-overview': 'overview', 'architecture-glossary': 'glossary', + 'releases/releases': 'releases', }; type SidebarItem = @@ -276,45 +277,47 @@ function generateMarkdown( ); // Process each item in the category - reorderedArray.forEach(item => { + for (const item of reorderedArray) { if (typeof item === 'string') { - // This is a direct page reference const fullDocPath = `${docPath}${mapDocPath(item, prefix)}`; if (!isEntryUnavailable(unavailableUrls, fullDocPath)) { - const {title, slug} = extractMetadataFromMarkdown(fullDocPath); - markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? item})\n`; + if (item.includes('/')) { + const pathChunks = item.split('/'); + if (pathChunks[0] === pathChunks[1]) { + markdown += appendPageLink(fullDocPath, prefix, pathChunks[0]); + continue; + } + } + markdown += appendPageLink(fullDocPath, prefix, item); } } else if (typeof item === 'object') { if (item.type === 'doc' && item.id) { - // This is a doc reference with an explicit ID const fullDocPath = `${docPath}${mapDocPath(item, prefix)}`; if (!isEntryUnavailable(unavailableUrls, fullDocPath)) { - const {title, slug} = extractMetadataFromMarkdown(fullDocPath); - markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? item.id})\n`; + markdown += appendPageLink(fullDocPath, prefix, item.id); } } else if (item.type === 'category' && Array.isArray(item.items)) { - // This is a category with nested items markdown += `#### ${item.label}\n\n`; item.items.forEach((nestedItem: SidebarItem) => { if (typeof nestedItem === 'string') { const fullDocPath = `${docPath}${mapDocPath(nestedItem, prefix)}`; if (!isEntryUnavailable(unavailableUrls, fullDocPath)) { - const {title, slug} = - extractMetadataFromMarkdown(fullDocPath); - markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? nestedItem})\n`; + markdown += appendPageLink(fullDocPath, prefix, nestedItem); } } else if (nestedItem.type === 'doc' && nestedItem.id) { const fullDocPath = `${docPath}${mapDocPath(nestedItem, prefix)}`; if (!isEntryUnavailable(unavailableUrls, fullDocPath)) { - const {title, slug} = - extractMetadataFromMarkdown(fullDocPath); - markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? nestedItem.id})\n`; + markdown += appendPageLink( + fullDocPath, + prefix, + nestedItem.id + ); } } }); } } - }); + } }); }); @@ -322,6 +325,11 @@ function generateMarkdown( return markdown.replace(/(#+ .*)\n/g, '\n$1\n').replace(/\n(\n)+/g, '\n\n'); } +function appendPageLink(fullDocPath: string, prefix: string, fsPath: string) { + const {title, slug} = extractMetadataFromMarkdown(fullDocPath); + return `- [${title}](${URL_PREFIX}${prefix}/${slug ?? fsPath})\n`; +} + async function generateOutput() { const results: {markdown: string; prefix: string}[] = []; const promises = [];