mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 13:12:44 +00:00
feat(docs): add Appendix glossary and page for undocumented tags
This commit is contained in:
1 parent
0e9e06eb8d
commit
c2a375fffc
5 files changed
+549
-15
No files matched your search
+15
-13
@@ -4,16 +4,19 @@
|
||||
* tag", read by the sides that must agree:
|
||||
*
|
||||
* - `components/ProblemBadges.astro` links a covered tag's badge to its
|
||||
* landing page, and every other tag's badge to its Appendix guide, `/appendix/<slug>`;
|
||||
* - `components/BacklinksList.astro` lists, under a landing or guide page,
|
||||
* every problem whose badge links there — both via `tagTarget()`;
|
||||
* - `apps/cli/sync.ts` creates a placeholder `content/appendix/<slug>.mdx` for
|
||||
* every tag a problem page carries that is NOT a key here.
|
||||
* landing page, and every other tag's badge to its Appendix card,
|
||||
* `/appendix#<slug>` (`appendix.ts`);
|
||||
* - `components/BacklinksList.astro` lists, under a landing page, every
|
||||
* problem whose badge links there — both via `tagTarget()`;
|
||||
* - `apps/cli/sync.ts` warns about a tag a problem page carries that is
|
||||
* neither a key here nor an Appendix term.
|
||||
*
|
||||
* Add a key when a campaign topic starts teaching a tag; its guide page is then
|
||||
* dead weight, delete it by hand. A tag naming two topics (DFS/BFS: tree and
|
||||
* Add a key when a campaign topic starts teaching a tag; its Appendix term is
|
||||
* then dead weight, delete it. A tag naming two topics (DFS/BFS: tree and
|
||||
* graph; DP: 1-D and grid) lists both; the badge picks per page.
|
||||
*/
|
||||
import { APPENDIX } from "./appendix.ts";
|
||||
|
||||
export const TOPIC_LANDINGS: Record<string, readonly string[]> = {
|
||||
"hash-table": ["/hash-table"],
|
||||
"prefix-sum": ["/prefix-sum"],
|
||||
@@ -43,9 +46,9 @@ export interface TopicTag {
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a problem page's badge for `tag` points: a root-relative landing or
|
||||
* guide route (the caller adds the base), or LeetCode's problem list when the
|
||||
* site serves neither, so a badge never links to a 404.
|
||||
* Where a problem page's badge for `tag` points: a root-relative landing
|
||||
* route or Appendix anchor (the caller adds the base), or LeetCode's problem
|
||||
* list when the site has neither, so a badge never links to a 404.
|
||||
*
|
||||
* A tag naming two landings links to the page's own topic — its route's first
|
||||
* segment — when that is one of them; otherwise DFS/BFS prefer the tree topic
|
||||
@@ -55,13 +58,12 @@ export function tagTarget(
|
||||
tag: TopicTag,
|
||||
page: { route: string; tags: readonly TopicTag[] },
|
||||
served: ReadonlySet<string>,
|
||||
): { href: string; kind: "landing" | "guide" | "external" } {
|
||||
): { href: string; kind: "landing" | "appendix" | "external" } {
|
||||
const landings = (TOPIC_LANDINGS[tag.slug] ?? []).filter((path) => served.has(path));
|
||||
const own = `/${page.route.split("/")[1]}`;
|
||||
const prefer = page.tags.some((t) => t.slug === "tree") ? "/tree-" : "/graph-";
|
||||
const landing = landings.includes(own) ? own : (landings.find((p) => p.startsWith(prefer)) ?? landings[0]);
|
||||
if (landing) return { href: landing, kind: "landing" };
|
||||
const guide = `/appendix/${tag.slug}`;
|
||||
if (served.has(guide)) return { href: guide, kind: "guide" };
|
||||
if (APPENDIX[tag.slug]) return { href: `/appendix#${tag.slug}`, kind: "appendix" };
|
||||
return { href: `https://leetcode.com/problem-list/${tag.slug}/`, kind: "external" };
|
||||
}
|
||||
Reference in new issue
Block a user