From a084303e03b28a9a069974766a6aada6aca1f12c Mon Sep 17 00:00:00 2001 From: lucyhartigan Date: Thu, 7 May 2026 23:05:11 -0400 Subject: [PATCH 1/3] first build script fix for anchor --- src/pages/_utils-node.ts | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/pages/_utils-node.ts b/src/pages/_utils-node.ts index 20ca1113f2..1deb4b7424 100644 --- a/src/pages/_utils-node.ts +++ b/src/pages/_utils-node.ts @@ -52,12 +52,12 @@ export const rewriteRelativeLink = (url: string): string => { return url; } else if (url.startsWith('#')||url.startsWith('/')) { // Skip rewriting for heading links and root-relative internal paths - updatedUrl = url; - } else { + return url; + } // Convert relative paths to '../' (because pages that started as files in the same directory // get turned into directories themselves, we need to go up a directory in the link) if (url.startsWith('./')) { - updatedUrl = `.${url}`; + updatedUrl = url.replace(/^\.\//, '../'); } else if (!url.startsWith('../')) { updatedUrl = `../${url}`; } else { @@ -65,20 +65,32 @@ export const rewriteRelativeLink = (url: string): string => { } // Relative links to md files should be turned into pages - if (updatedUrl.endsWith('.md')) { - updatedUrl = updatedUrl.replace(/\.md$/, ''); + // Ensure we handle anchors/query strings by splitting suffix, removing .md from base, rejoining parts + const firstSpecialIdx = (() => { + const qi = updatedUrl.indexOf('?'); + const hi = updatedUrl.indexOf('#'); + if (qi === -1 && hi === -1) return -1; + if (qi === -1) return hi; + if (hi === -1) return qi; + return Math.min(qi, hi); + })(); + + const basePart = firstSpecialIdx === -1 ? updatedUrl : updatedUrl.slice(0, firstSpecialIdx); + const suffixPart = firstSpecialIdx === -1 ? "" : updatedUrl.slice(firstSpecialIdx); // includes ? or # + + let normalizedBase = basePart; + if (normalizedBase.endsWith('.md')) { + normalizedBase = normalizedBase.replace(/\.md$/, ''); } - } - // Add a trailing / if the link isn't to a file and does not have query params or a hash reference - if ( - !updatedUrl.endsWith('/') && - !/(\.\w+)$/.exec(updatedUrl) && - !updatedUrl.includes('?') && - !/#([\w-]+)$/.exec(updatedUrl) - ) { - updatedUrl += '/'; - } + // Add trailing slash to the base if it is a directory + if (!normalizedBase.endsWith('/') && !/(\.\w+)$/.exec(normalizedBase)) { + normalizedBase += '/'; + } - return updatedUrl; -}; + updatedUrl = normalizedBase + suffixPart; + + // (no further trailing-slash rewriting; base+suffix already normalized above) + + return updatedUrl; + }; From 68dffd08305c181781e77f845865250f9950cef4 Mon Sep 17 00:00:00 2001 From: lucyhartigan Date: Thu, 7 May 2026 23:15:50 -0400 Subject: [PATCH 2/3] cleanup relative path logic --- src/pages/_utils-node.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/_utils-node.ts b/src/pages/_utils-node.ts index 1deb4b7424..6c675c2eed 100644 --- a/src/pages/_utils-node.ts +++ b/src/pages/_utils-node.ts @@ -57,7 +57,7 @@ export const rewriteRelativeLink = (url: string): string => { // Convert relative paths to '../' (because pages that started as files in the same directory // get turned into directories themselves, we need to go up a directory in the link) if (url.startsWith('./')) { - updatedUrl = url.replace(/^\.\//, '../'); + updatedUrl = `.${url}` } else if (!url.startsWith('../')) { updatedUrl = `../${url}`; } else { @@ -90,7 +90,5 @@ export const rewriteRelativeLink = (url: string): string => { updatedUrl = normalizedBase + suffixPart; - // (no further trailing-slash rewriting; base+suffix already normalized above) - return updatedUrl; }; From ae4f17a6c586cc016272aece4dde706c1d0647a3 Mon Sep 17 00:00:00 2001 From: lucyhartigan Date: Thu, 7 May 2026 23:19:13 -0400 Subject: [PATCH 3/3] fix semicolon error --- src/pages/_utils-node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/_utils-node.ts b/src/pages/_utils-node.ts index 6c675c2eed..b3b771eb3a 100644 --- a/src/pages/_utils-node.ts +++ b/src/pages/_utils-node.ts @@ -57,7 +57,7 @@ export const rewriteRelativeLink = (url: string): string => { // Convert relative paths to '../' (because pages that started as files in the same directory // get turned into directories themselves, we need to go up a directory in the link) if (url.startsWith('./')) { - updatedUrl = `.${url}` + updatedUrl = `.${url}`; } else if (!url.startsWith('../')) { updatedUrl = `../${url}`; } else {