From 8979f2928c905eb0dec5bf184d1e4a6ba6ec42a5 Mon Sep 17 00:00:00 2001 From: forcetrainer Date: Thu, 8 Jan 2026 11:57:04 -0500 Subject: [PATCH] fix: handle /docs/ prefix in link validator Update resolveLink to strip /docs/ prefix from repo-relative links before checking if files exist. Co-Authored-By: Claude Opus 4.5 --- tools/validate-doc-links.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/validate-doc-links.js b/tools/validate-doc-links.js index 6778d958..5b0a018a 100644 --- a/tools/validate-doc-links.js +++ b/tools/validate-doc-links.js @@ -102,11 +102,17 @@ function extractAnchors(content) { /** * Resolve a site-relative link to a file path + * /docs/how-to/installation/install-bmad.md -> docs/how-to/installation/install-bmad.md * /how-to/installation/install-bmad/ -> docs/how-to/installation/install-bmad.md or .../index.md */ function resolveLink(siteRelativePath) { // Strip anchor and query - const checkPath = siteRelativePath.split('#')[0].split('?')[0]; + let checkPath = siteRelativePath.split('#')[0].split('?')[0]; + + // Strip /docs/ prefix if present (repo-relative links) + if (checkPath.startsWith('/docs/')) { + checkPath = checkPath.slice(5); // Remove '/docs' but keep leading '/' + } if (checkPath.endsWith('/')) { // Could be file.md or directory/index.md @@ -118,11 +124,11 @@ function resolveLink(siteRelativePath) { return null; } - // Direct path + // Direct path (e.g., /path/file.md) const direct = path.join(DOCS_ROOT, checkPath); if (fs.existsSync(direct)) return direct; - // Try with .md + // Try with .md extension const withMd = direct + '.md'; if (fs.existsSync(withMd)) return withMd;