mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
17 lines
844 B
JavaScript
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)`);
|