From 3014ba4b99f1b2c724a023faaab748dd431e94ad Mon Sep 17 00:00:00 2001 From: Darius Cepulis Date: Thu, 2 Apr 2026 08:51:30 -0500 Subject: [PATCH] fix(site): use absolute URLs in generated LLM markdown files (#1200) Co-authored-by: Claude Opus 4.6 (1M context) --- site/integrations/llms-markdown.ts | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/site/integrations/llms-markdown.ts b/site/integrations/llms-markdown.ts index a1d7a213..25a4fc1f 100644 --- a/site/integrations/llms-markdown.ts +++ b/site/integrations/llms-markdown.ts @@ -14,9 +14,14 @@ interface PageEntry { } export default function llmsMarkdown(): AstroIntegration { + let siteUrl = ''; + return { name: 'llms-markdown', hooks: { + 'astro:config:done': ({ config }) => { + siteUrl = config.site?.replace(/\/$/, '') ?? ''; + }, 'astro:build:done': async ({ dir, pages, logger }) => { const siteDir = fileURLToPath(dir); const turndown = new TurndownService({ @@ -125,7 +130,7 @@ export default function llmsMarkdown(): AstroIntegration { const frameworks: string[] = []; for (const [fw, fwPages] of docsByFramework) { frameworks.push(fw); - const subIndex = generateDocsIndex(fw, fwPages); + const subIndex = generateDocsIndex(fw, fwPages, siteUrl); const subIndexPath = join(siteDir, 'docs', 'framework', fw, 'llms.txt'); await mkdir(dirname(subIndexPath), { recursive: true }); await writeFile(subIndexPath, subIndex, 'utf-8'); @@ -133,14 +138,14 @@ export default function llmsMarkdown(): AstroIntegration { // Write blog sub-index if (blogPages.length > 0) { - const blogIndex = generateBlogIndex(blogPages); + const blogIndex = generateBlogIndex(blogPages, siteUrl); const blogIndexPath = join(siteDir, 'blog', 'llms.txt'); await mkdir(dirname(blogIndexPath), { recursive: true }); await writeFile(blogIndexPath, blogIndex, 'utf-8'); } // Write root llms.txt index - const rootIndex = generateRootIndex(frameworks, blogPages.length > 0, otherPages); + const rootIndex = generateRootIndex(frameworks, blogPages.length > 0, otherPages, siteUrl); const rootIndexPath = join(siteDir, 'llms.txt'); await writeFile(rootIndexPath, rootIndex, 'utf-8'); @@ -153,20 +158,20 @@ export default function llmsMarkdown(): AstroIntegration { }; } -function generateRootIndex(frameworks: string[], hasBlog: boolean, otherPages: PageEntry[]): string { +function generateRootIndex(frameworks: string[], hasBlog: boolean, otherPages: PageEntry[], siteUrl: string): string { let content = `# Video.js v10\n\n`; content += `> Modern video player framework with multi-platform support\n\n`; content += `## Documentation\n\n`; for (const fw of [...frameworks].sort()) { const label = fw.charAt(0).toUpperCase() + fw.slice(1); - content += `- [${label} Docs](/docs/framework/${fw}/llms.txt)\n`; + content += `- [${label} Docs](${siteUrl}/docs/framework/${fw}/llms.txt)\n`; } content += `\n`; if (hasBlog) { content += `## Blog\n\n`; - content += `- [Blog Posts](/blog/llms.txt)\n\n`; + content += `- [Blog Posts](${siteUrl}/blog/llms.txt)\n\n`; } if (otherPages.length > 0) { @@ -174,9 +179,9 @@ function generateRootIndex(frameworks: string[], hasBlog: boolean, otherPages: P const sorted = [...otherPages].sort((a, b) => a.pathname.localeCompare(b.pathname)); for (const page of sorted) { if (page.description) { - content += `- [${page.title}](${page.pathname}.md): ${page.description}\n`; + content += `- [${page.title}](${siteUrl}${page.pathname}.md): ${page.description}\n`; } else { - content += `- [${page.title}](${page.pathname}.md)\n`; + content += `- [${page.title}](${siteUrl}${page.pathname}.md)\n`; } } content += `\n`; @@ -185,16 +190,16 @@ function generateRootIndex(frameworks: string[], hasBlog: boolean, otherPages: P return content; } -function generateDocsIndex(framework: string, pages: PageEntry[]): string { +function generateDocsIndex(framework: string, pages: PageEntry[], siteUrl: string): string { const label = framework.charAt(0).toUpperCase() + framework.slice(1); let content = `# Video.js v10 — ${label} Documentation\n\n`; const sorted = [...pages].sort((a, b) => a.pathname.localeCompare(b.pathname)); for (const page of sorted) { if (page.description) { - content += `- [${page.title}](${page.pathname}.md): ${page.description}\n`; + content += `- [${page.title}](${siteUrl}${page.pathname}.md): ${page.description}\n`; } else { - content += `- [${page.title}](${page.pathname}.md)\n`; + content += `- [${page.title}](${siteUrl}${page.pathname}.md)\n`; } } content += `\n`; @@ -202,7 +207,7 @@ function generateDocsIndex(framework: string, pages: PageEntry[]): string { return content; } -function generateBlogIndex(pages: PageEntry[]): string { +function generateBlogIndex(pages: PageEntry[], siteUrl: string): string { let content = `# Video.js v10 — Blog\n\n`; // Newest first @@ -215,9 +220,9 @@ function generateBlogIndex(pages: PageEntry[]): string { for (const post of sorted) { if (post.description) { - content += `- [${post.title}](${post.pathname}.md): ${post.description}\n`; + content += `- [${post.title}](${siteUrl}${post.pathname}.md): ${post.description}\n`; } else { - content += `- [${post.title}](${post.pathname}.md)\n`; + content += `- [${post.title}](${siteUrl}${post.pathname}.md)\n`; } } content += `\n`;