From 05b8ffd39df96fb818b1a651a8f47de94da7b746 Mon Sep 17 00:00:00 2001 From: ydliu2 Date: Sun, 5 Apr 2026 12:38:10 +0800 Subject: [PATCH] fix(docs): rewrite exported home links for pages --- scripts/export-docs-site.mjs | 2 ++ scripts/export-docs-site.test.mjs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/export-docs-site.mjs b/scripts/export-docs-site.mjs index 7af5ead52d..3f354387ff 100644 --- a/scripts/export-docs-site.mjs +++ b/scripts/export-docs-site.mjs @@ -187,6 +187,7 @@ export function rewriteTextAsset(content, basePath) { const pathPrefixPattern = /(["'`])\/(?=(_next\/|docs\/|favicons\/|sitemap\.xml|robots\.txt))/g; const rootHrefPattern = /(href\s*[=:]\s*["'])\/(?=["'])/g; + const rootHrefLiteralPattern = /(["']?href["']\s*:\s*["'])\/(?=["'])/g; const cssUrlPattern = /url\(\s*\/(?=(_next\/|docs\/|favicons\/|sitemap\.xml|robots\.txt))/g; const cliEnvPattern = /NEXT_PUBLIC_ENV:(["'])cli\1/g; @@ -196,6 +197,7 @@ export function rewriteTextAsset(content, basePath) { if (basePath) { rewritten = rewritten.replace(pathPrefixPattern, `$1${basePath}/`); rewritten = rewritten.replace(rootHrefPattern, `$1${basePath}/`); + rewritten = rewritten.replace(rootHrefLiteralPattern, `$1${basePath}/`); rewritten = rewritten.replace(cssUrlPattern, `url(${basePath}/`); } diff --git a/scripts/export-docs-site.test.mjs b/scripts/export-docs-site.test.mjs index b4c7db4a6a..7a5fae8d8a 100644 --- a/scripts/export-docs-site.test.mjs +++ b/scripts/export-docs-site.test.mjs @@ -69,6 +69,7 @@ describe('rewriteTextAsset', () => { const original = [ 'const env={NEXT_PUBLIC_ENV:"cli",NEXT_PUBLIC_IS_LOCAL_CLIENT:"true"};', 'const asset="/_next/static/chunk.js";', + 'const home={href:"/"};', ].join('\n'); const rewritten = rewriteTextAsset(original, '/claude-code'); @@ -76,5 +77,6 @@ describe('rewriteTextAsset', () => { expect(rewritten).toContain('NEXT_PUBLIC_ENV:"production"'); expect(rewritten).toContain('NEXT_PUBLIC_IS_LOCAL_CLIENT:"false"'); expect(rewritten).toContain('"/claude-code/_next/static/chunk.js"'); + expect(rewritten).toContain('href:"/claude-code/"'); }); });