mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 13:12:44 +00:00
refactor(cli): clarify topic folder handling and remove unused groupFolder helper
This commit is contained in:
1 parent
2e5d991d47
commit
891a1f0c5a
1 file changed
+10
-8
+10
-8
@@ -12,11 +12,17 @@
|
|||||||
* render as a plain fence.
|
* render as a plain fence.
|
||||||
*
|
*
|
||||||
* Two classifications, two homes. The sidebar group is the campaign TOPIC
|
* Two classifications, two homes. The sidebar group is the campaign TOPIC
|
||||||
* from the README table (`(tree-dfs)/`, ordered by topic number via a
|
* from the README table (`tree-dfs/`, ordered by topic number via a
|
||||||
* script-owned `meta.ts`); the page badge is the data-structure CATEGORY the
|
* script-owned `meta.ts`); the page badge is the data-structure CATEGORY the
|
||||||
* file sits under in `work/1/<Difficulty>/<Category>/`. A problem outside the
|
* file sits under in `work/1/<Difficulty>/<Category>/`. A problem outside the
|
||||||
* plan (warm-ups) has no topic, so it groups under its category instead.
|
* plan (warm-ups) has no topic, so it groups under its category instead.
|
||||||
*
|
*
|
||||||
|
* Topic folders are real route segments (`/tree-dfs/invert-binary-tree`), not
|
||||||
|
* `(group)` folders, so a hand-written `index.mdx` in one is the topic's
|
||||||
|
* landing page at `/tree-dfs` and Blume links the sidebar group row to it.
|
||||||
|
* Sync never writes or moves an `index.mdx`, and never removes a folder that
|
||||||
|
* still holds one.
|
||||||
|
*
|
||||||
* Only the first-solve bucket is read: work/3 and work/7 hold blind re-solves
|
* 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
|
* of problems whose page already exists (see work.ts), and a fresh scaffold
|
||||||
* there would otherwise wipe the page's `## Solution`.
|
* there would otherwise wipe the page's `## Solution`.
|
||||||
@@ -190,11 +196,6 @@ async function readmeTopics(): Promise<Map<number, Topic>> {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** `(group)` folder name: route-transparent in Blume, so only the sidebar sees it. */
|
|
||||||
function groupFolder(topic: Topic): string {
|
|
||||||
return `(${topic.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")})`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Blume folder meta: exact topic label (the folder slug loses `/` and case) and curriculum order. */
|
/** Blume folder meta: exact topic label (the folder slug loses `/` and case) and curriculum order. */
|
||||||
function groupMeta(topic: Topic): string {
|
function groupMeta(topic: Topic): string {
|
||||||
const order = topic.order === undefined ? "" : `, order: ${topic.order}`;
|
const order = topic.order === undefined ? "" : `, order: ${topic.order}`;
|
||||||
@@ -422,11 +423,12 @@ const vacated = new Set<string>(); // folders a page moved out of; removed below
|
|||||||
for (const sol of ordered) {
|
for (const sol of ordered) {
|
||||||
const langs = Object.keys(sol.code).sort().join("+");
|
const langs = Object.keys(sol.code).sort().join("+");
|
||||||
const workRef = `${sol.num}.${sol.slug} (${langs})`;
|
const workRef = `${sol.num}.${sol.slug} (${langs})`;
|
||||||
// (topic) group folder + leetcode-number prefix: numeric sidebar order, both stripped from the URL.
|
// <topic>/ folder (a real route segment, so its index.mdx is the topic landing
|
||||||
|
// page) + leetcode-number prefix: numeric sidebar order, prefix stripped from the URL.
|
||||||
// An unplanned problem's category may share a folder with a numbered topic
|
// An unplanned problem's category may share a folder with a numbered topic
|
||||||
// (`Hash Table` warm-ups under topic 1); the numbered one owns the meta.
|
// (`Hash Table` warm-ups under topic 1); the numbered one owns the meta.
|
||||||
const topic = topics.get(sol.num) ?? { name: sol.category };
|
const topic = topics.get(sol.num) ?? { name: sol.category };
|
||||||
const group = groupFolder(topic);
|
const group = topic.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
||||||
if (groups.get(group)?.order === undefined) groups.set(group, topic);
|
if (groups.get(group)?.order === undefined) groups.set(group, topic);
|
||||||
const name = `${group}/${sol.num}-${sol.slug}.mdx`;
|
const name = `${group}/${sol.num}-${sol.slug}.mdx`;
|
||||||
const existing = pages.get(sol.num);
|
const existing = pages.get(sol.num);
|
||||||
|
|||||||
Reference in new issue
Block a user