Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/export-docs-site.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}/`);
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/export-docs-site.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ 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');

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/"');
});
});
Loading