mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 21:22:43 +00:00
feat(components): enhance tag color computation for problem badges
This commit is contained in:
1 parent
d5496581df
commit
3b9079f87f
1 file changed
+21
-6
@@ -17,9 +17,10 @@
|
|||||||
* `PageFooter` backlinks list reads the same answer. Each tag badge is a
|
* `PageFooter` backlinks list reads the same answer. Each tag badge is a
|
||||||
* pill carrying the icon its target shows in the sidebar (the topic's
|
* pill carrying the icon its target shows in the sidebar (the topic's
|
||||||
* `meta.ts` icon, the guide's `icon:`) and the tag's own colour
|
* `meta.ts` icon, the guide's `icon:`) and the tag's own colour
|
||||||
* (`lib/tag-colors.ts`), assigned over every tag the site has a page for,
|
* (`lib/tag-colors.ts`), assigned over every tag the site has a page for —
|
||||||
* so no two tags share one. A tag with no page (the LeetCode-list fallback)
|
* no two tags share one, and tags that share problem pages are spread
|
||||||
* stays gray and iconless.
|
* furthest apart. A tag with no page (the LeetCode-list fallback) stays
|
||||||
|
* gray and iconless.
|
||||||
* - `video:` (problem pages, written by `apps/cli/videos.ts`) is the NeetCode
|
* - `video:` (problem pages, written by `apps/cli/videos.ts`) is the NeetCode
|
||||||
* walkthrough's YouTube id, the red "Explanation" badge at the end of the row.
|
* walkthrough's YouTube id, the red "Explanation" badge at the end of the row.
|
||||||
* - `list:` (guide pages, written by sync on create) is the tag's LeetCode
|
* - `list:` (guide pages, written by sync on create) is the tag's LeetCode
|
||||||
@@ -62,11 +63,25 @@ const walk = (nodes: NavNode[]) => {
|
|||||||
};
|
};
|
||||||
walk(data.navigation.sidebar);
|
walk(data.navigation.sidebar);
|
||||||
|
|
||||||
// Every tag with a page: the ones a landing teaches, plus every served guide.
|
// Every tag with a page — the ones a landing teaches, plus every served guide —
|
||||||
const colors = tagColors([
|
// coloured against how problem pages (`<num>. <name>` titles, the shape sync
|
||||||
|
// writes) combine them. Only a page with tags needs the answer.
|
||||||
|
const colors = tags.length
|
||||||
|
? tagColors(
|
||||||
|
[
|
||||||
...Object.keys(TOPIC_LANDINGS),
|
...Object.keys(TOPIC_LANDINGS),
|
||||||
...[...served].flatMap((path) => path.match(/^\/guides\/([^/]+)$/u)?.slice(1) ?? []),
|
...[...served].flatMap((path) => path.match(/^\/guides\/([^/]+)$/u)?.slice(1) ?? []),
|
||||||
]);
|
],
|
||||||
|
await Promise.all(
|
||||||
|
data.routes
|
||||||
|
.filter((r: { title: string }) => /^\d+\.\s/u.test(r.title))
|
||||||
|
.map(async (r: { collection: string; entryId: string }) => {
|
||||||
|
const page = await getEntry(r.collection, r.entryId);
|
||||||
|
return (page?.data.topics ?? []).map((t: TopicTag) => t.slug);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: new Map<string, string>();
|
||||||
|
|
||||||
const badges = tags.map((tag) => {
|
const badges = tags.map((tag) => {
|
||||||
const target = tagTarget(tag, { route, tags }, served);
|
const target = tagTarget(tag, { route, tags }, served);
|
||||||
|
|||||||
Reference in new issue
Block a user