mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 21:22:43 +00:00
feat(cli): improve guide file placement and handling in sync script
This commit is contained in:
1 parent
dd929cca6c
commit
bc6eb3e66b
1 file changed
+13
-5
+13
-5
@@ -22,7 +22,10 @@
|
|||||||
* `apps/docs/topic-landings.ts`) gets a placeholder guide page,
|
* `apps/docs/topic-landings.ts`) gets a placeholder guide page,
|
||||||
* `guides/<slug>.mdx`, with `list:` pointing at LeetCode's problem list for
|
* `guides/<slug>.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
|
* 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/<slug>` 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/`,
|
* 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
|
* 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
|
// 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
|
// (an empty file counts as missing) and never rewritten. A guide is found by
|
||||||
// page carries any more is left alone: it is hand-owned.
|
// 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()]
|
const guideTags = [...tags.values()]
|
||||||
.filter((tag) => !TOPIC_LANDINGS[tag.slug])
|
.filter((tag) => !TOPIC_LANDINGS[tag.slug])
|
||||||
.sort((a, b) => a.slug.localeCompare(b.slug));
|
.sort((a, b) => a.slug.localeCompare(b.slug));
|
||||||
|
const guideFiles = new Map<string, string>(); // 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) {
|
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;
|
if ((await file.exists()) && file.size > 0) continue;
|
||||||
await Bun.write(file, guidePage(tag));
|
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
|
// Phase metas: created when missing (an empty file counts as missing), never
|
||||||
|
|||||||
Reference in new issue
Block a user