diff --git a/apps/cli/sync.ts b/apps/cli/sync.ts index b5472a5..2592235 100755 --- a/apps/cli/sync.ts +++ b/apps/cli/sync.ts @@ -22,7 +22,10 @@ * `apps/docs/topic-landings.ts`) gets a placeholder guide page, * `guides/.mdx`, with `list:` pointing at LeetCode's problem list for * the tag. Created once (a missing or empty file), then hand-owned; the tag's - * badge on a problem page links to it. + * badge on a problem page links to it. A guide may be filed into a category + * `(group)` folder (e.g. `guides/(2-algorithms)/`) — no route segment, so + * `/guides/` holds — and is found there by slug; a new placeholder + * lands at the `guides/` root for a human to file. * * The sidebar group is the campaign TOPIC from the README table (`tree-dfs/`, * ordered by topic number via a script-owned `meta.ts`). A problem outside the @@ -723,16 +726,21 @@ for (const sol of ordered) { } // One guide page per tag that no campaign topic teaches, created when missing -// (an empty file counts as missing) and never rewritten. A guide whose tag no -// page carries any more is left alone: it is hand-owned. +// (an empty file counts as missing) and never rewritten. A guide is found by +// slug anywhere under guides/ — a human files it into a category `(group)`, +// which leaves its route alone — and a new one lands at the guides/ root. A +// guide whose tag no page carries any more is left alone: it is hand-owned. const guideTags = [...tags.values()] .filter((tag) => !TOPIC_LANDINGS[tag.slug]) .sort((a, b) => a.slug.localeCompare(b.slug)); +const guideFiles = new Map(); // slug -> path relative to DOCS +for await (const rel of new Bun.Glob("guides/**/*.mdx").scan(DOCS)) guideFiles.set(basename(rel, ".mdx"), rel); for (const tag of guideTags) { - const file = Bun.file(join(DOCS, "guides", `${tag.slug}.mdx`)); + const rel = guideFiles.get(tag.slug) ?? `guides/${tag.slug}.mdx`; + const file = Bun.file(join(DOCS, rel)); if ((await file.exists()) && file.size > 0) continue; await Bun.write(file, guidePage(tag)); - report.push([`tag ${tag.slug}`, `guides/${tag.slug}.mdx`, "created"]); + report.push([`tag ${tag.slug}`, rel, "created"]); } // Phase metas: created when missing (an empty file counts as missing), never