docs(docs): add BacklinksList component and shared tagTarget logic for badge routing, update docs pages

This commit is contained in:
Prad Nukala committed 2026-09-29 15:12:54 -04:00
1 parent eea8d242e0
commit 40e965aa06
5 files changed
+161 -23

No files matched your search

+7 -22
View File
@@ -10,33 +10,23 @@
* topic tags. A tag the campaign teaches (`topic-landings.ts`) links to that
* topic's landing page and reads accent; any other tag links to its guide
* page, `/guides/<slug>` (sync creates one per such tag), and reads neutral.
* `tagTarget()` picks the route (and between two landings, e.g. DFS); the
* `PageFooter` backlinks list reads the same answer.
* - `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.
* - `list:` (guide pages, written by sync on create) is the tag's LeetCode
* problem list, an orange "LeetCode list" badge.
*
* A tag naming two campaign topics (`Depth-First Search` is both Tree DFS and
* Graph DFS) 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 for a problem
* LeetCode also tags `Tree` and the graph topic for the rest. A route the site
* does not serve (a landing or guide page removed) falls back to LeetCode's
* problem list for the tag, so a badge never links to a 404.
*/
import { getEntry } from "astro:content";
import data from "blume:data";
import Badge from "blume/components/content/Badge.astro";
import { withBase } from "blume/components/islands/base-path.ts";
import { TOPIC_LANDINGS } from "../topic-landings.ts";
import { tagTarget, type TopicTag } from "../topic-landings.ts";
interface Props {
route: string;
}
interface TopicTag {
name: string;
slug: string;
}
const { route } = Astro.props;
const at = data.routes.find((r: { path: string }) => r.path === route);
const entry = at ? await getEntry(at.collection, at.entryId) : undefined;
@@ -44,17 +34,12 @@ const tags: TopicTag[] = entry?.data.topics ?? [];
const video: string | undefined = entry?.data.video;
const list: string | undefined = entry?.data.list;
const served = new Set(data.routes.map((r: { path: string }) => r.path));
const own = `/${route.split("/")[1]}`;
const prefer = tags.some((t) => t.slug === "tree") ? "/tree-" : "/graph-";
const served = new Set<string>(data.routes.map((r: { path: string }) => r.path));
const badges = tags.map((tag) => {
const landings = (TOPIC_LANDINGS[tag.slug] ?? []).filter((path) => served.has(path));
const landing = landings.includes(own) ? own : (landings.find((p) => p.startsWith(prefer)) ?? landings[0]);
if (landing) return { name: tag.name, href: withBase(landing), accent: true, external: false };
const guide = `/guides/${tag.slug}`;
if (served.has(guide)) return { name: tag.name, href: withBase(guide), accent: false, external: false };
return { name: tag.name, href: `https://leetcode.com/problem-list/${tag.slug}/`, accent: false, external: true };
const target = tagTarget(tag, { route, tags }, served);
const external = target.kind === "external";
return { name: tag.name, href: external ? target.href : withBase(target.href), accent: target.kind === "landing", external };
});
const linkClass = "no-underline transition-opacity hover:opacity-80";