Files
SnapOtter/apps/landing/scripts/generate-redirects.mjs
T

17 lines
844 B
JavaScript

// 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)`);