Skip to content

Commit e862d00

Browse files
JacobCoffeeclaude
andcommitted
fix redirect targets missing base path on GitHub Pages
Astro prepends base to redirect sources but not targets, so the meta-refresh URL was /<year>/<slug> instead of /python-insider-blog/... Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 88cffac commit e862d00

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

astro.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import remarkPythonRefs from "./src/plugins/remark-python-refs";
99
const isDev = process.env.NODE_ENV === "development" || process.argv.includes("dev");
1010

1111
// Load redirects generated by the migration script
12+
// Astro prepends `base` to the redirect source but not the target,
13+
// so we prepend it ourselves for non-root deployments.
14+
const base = isDev ? "" : "/python-insider-blog";
1215
let redirects: Record<string, string> = {};
1316
try {
1417
const redirectsPath = new URL("./src/data/redirects.json", import.meta.url);
15-
redirects = JSON.parse(fs.readFileSync(redirectsPath, "utf-8"));
18+
const raw: Record<string, string> = JSON.parse(fs.readFileSync(redirectsPath, "utf-8"));
19+
for (const [from, to] of Object.entries(raw)) {
20+
redirects[from] = `${base}${to}`;
21+
}
1622
} catch {
1723
// No redirects file yet (run migration first)
1824
}

0 commit comments

Comments
 (0)