Skip to content

Commit 0645ccb

Browse files
authored
scripts: fix incorrect Releases page link in LLMS.txt (#4872)
1 parent 9d1549a commit 0645ccb

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

scripts/src/generate-llms-txt.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const INPUT_FILE_PATHS = [
3636
const SLUG_TO_URL = {
3737
'architecture-overview': 'overview',
3838
'architecture-glossary': 'glossary',
39+
'releases/releases': 'releases',
3940
};
4041

4142
type SidebarItem =
@@ -276,52 +277,59 @@ function generateMarkdown(
276277
);
277278

278279
// Process each item in the category
279-
reorderedArray.forEach(item => {
280+
for (const item of reorderedArray) {
280281
if (typeof item === 'string') {
281-
// This is a direct page reference
282282
const fullDocPath = `${docPath}${mapDocPath(item, prefix)}`;
283283
if (!isEntryUnavailable(unavailableUrls, fullDocPath)) {
284-
const {title, slug} = extractMetadataFromMarkdown(fullDocPath);
285-
markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? item})\n`;
284+
if (item.includes('/')) {
285+
const pathChunks = item.split('/');
286+
if (pathChunks[0] === pathChunks[1]) {
287+
markdown += appendPageLink(fullDocPath, prefix, pathChunks[0]);
288+
continue;
289+
}
290+
}
291+
markdown += appendPageLink(fullDocPath, prefix, item);
286292
}
287293
} else if (typeof item === 'object') {
288294
if (item.type === 'doc' && item.id) {
289-
// This is a doc reference with an explicit ID
290295
const fullDocPath = `${docPath}${mapDocPath(item, prefix)}`;
291296
if (!isEntryUnavailable(unavailableUrls, fullDocPath)) {
292-
const {title, slug} = extractMetadataFromMarkdown(fullDocPath);
293-
markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? item.id})\n`;
297+
markdown += appendPageLink(fullDocPath, prefix, item.id);
294298
}
295299
} else if (item.type === 'category' && Array.isArray(item.items)) {
296-
// This is a category with nested items
297300
markdown += `#### ${item.label}\n\n`;
298301
item.items.forEach((nestedItem: SidebarItem) => {
299302
if (typeof nestedItem === 'string') {
300303
const fullDocPath = `${docPath}${mapDocPath(nestedItem, prefix)}`;
301304
if (!isEntryUnavailable(unavailableUrls, fullDocPath)) {
302-
const {title, slug} =
303-
extractMetadataFromMarkdown(fullDocPath);
304-
markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? nestedItem})\n`;
305+
markdown += appendPageLink(fullDocPath, prefix, nestedItem);
305306
}
306307
} else if (nestedItem.type === 'doc' && nestedItem.id) {
307308
const fullDocPath = `${docPath}${mapDocPath(nestedItem, prefix)}`;
308309
if (!isEntryUnavailable(unavailableUrls, fullDocPath)) {
309-
const {title, slug} =
310-
extractMetadataFromMarkdown(fullDocPath);
311-
markdown += `- [${title}](${URL_PREFIX}${prefix}/${slug ?? nestedItem.id})\n`;
310+
markdown += appendPageLink(
311+
fullDocPath,
312+
prefix,
313+
nestedItem.id
314+
);
312315
}
313316
}
314317
});
315318
}
316319
}
317-
});
320+
}
318321
});
319322
});
320323

321324
// Format and cleanup whitespaces
322325
return markdown.replace(/(#+ .*)\n/g, '\n$1\n').replace(/\n(\n)+/g, '\n\n');
323326
}
324327

328+
function appendPageLink(fullDocPath: string, prefix: string, fsPath: string) {
329+
const {title, slug} = extractMetadataFromMarkdown(fullDocPath);
330+
return `- [${title}](${URL_PREFIX}${prefix}/${slug ?? fsPath})\n`;
331+
}
332+
325333
async function generateOutput() {
326334
const results: {markdown: string; prefix: string}[] = [];
327335
const promises = [];

0 commit comments

Comments
 (0)