feat(landing): generate 301 redirects for old tool URLs; fix robots sitemap reference

This commit is contained in:
SnapOtter
2026-06-20 23:56:03 +08:00
parent f158be6aaa
commit 0051655bbf
4 changed files with 333 additions and 1 deletions
@@ -0,0 +1,16 @@
// Generates public/_redirects (Cloudflare Pages) mapping old flat tool URLs
// (/tools/<id>) to the new section-nested URLs (/tools/<section>/<id>/).
// Both slash variants are emitted because Cloudflare matches paths exactly.
import { writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { TOOLS, toolSection } from "@snapotter/shared";
const lines = ["# Generated by scripts/generate-redirects.mjs -- do not edit by hand"];
for (const tool of TOOLS) {
const to = `/tools/${toolSection(tool)}/${tool.id}/`;
lines.push(`/tools/${tool.id}/ ${to} 301`);
lines.push(`/tools/${tool.id} ${to} 301`);
}
const out = fileURLToPath(new URL("../public/_redirects", import.meta.url));
writeFileSync(out, `${lines.join("\n")}\n`);
console.log(`wrote ${out} (${TOOLS.length} tools, ${lines.length - 1} redirect lines)`);