diff --git a/apps/cli/sync.ts b/apps/cli/sync.ts index 11f44ae..777de88 100755 --- a/apps/cli/sync.ts +++ b/apps/cli/sync.ts @@ -29,6 +29,11 @@ * Only the first-solve bucket is read: work/3 and work/7 hold blind re-solves * of problems whose page already exists (see work.ts), and a fresh scaffold * there would otherwise wipe the page's `## Solution`. + * + * Every page also gets a short link: `/` → `//` (so + * `/leetcode/217` opens Contains Duplicate). The rules live in the generated + * `apps/docs/redirects.ts`, which `blume.config.ts` imports — Blume takes exact + * root-relative paths and prepends the deployment base itself. */ import { mkdir, readdir, rename, rmdir, unlink } from "node:fs/promises"; import { basename, dirname, join } from "node:path"; @@ -36,6 +41,7 @@ import { basename, dirname, join } from "node:path"; const ROOT = join(import.meta.dir, "..", ".."); const WORK = join(ROOT, "work", "1"); const DOCS = join(ROOT, "apps", "docs", "content"); +const REDIRECTS = join(ROOT, "apps", "docs", "redirects.ts"); type Lang = "js" | "py"; @@ -533,6 +539,7 @@ const ordered = [...solutions.values()].sort((a, b) => a.num - b.num); const groups = new Map(); // topic folder -> topic, for meta.ts const phases = new Map(); // phase folder -> phase, for meta.ts const vacated = new Set(); // folders a page moved out of; removed below if empty +const redirects: string[] = []; // `{ from: "/", to: "//" }` rows, numeric order for (const sol of ordered) { const langs = Object.keys(sol.code).sort().join("+"); @@ -573,6 +580,24 @@ for (const sol of ordered) { await Bun.write(join(DOCS, name), renderPage(sol)); report.push([workRef, name, "created"]); } + // The route drops the phase `(group)` and the page's number prefix. + redirects.push(` { from: "/${sol.num}", to: ${JSON.stringify(`/${slugify(topic.name)}/${sol.slug}`)} },`); +} + +// Script-owned short links, one per page; imported by blume.config.ts. +{ + const module = [ + "// Generated by `bun run sync` (apps/cli/sync.ts) — do not edit.", + "// `/leetcode/` → that problem's page; exact paths, base added by Blume.", + "export default [", + ...redirects, + "];", + "", + ].join("\n"); + if (!(await Bun.file(REDIRECTS).exists()) || (await Bun.file(REDIRECTS).text()) !== module) { + await Bun.write(REDIRECTS, module); + report.push([`${redirects.length} redirects`, "apps/docs/redirects.ts", "written"]); + } } // Script-owned folder metas — one per live phase and topic folder — rewritten