refactor(website): match subcategory by URL prefix instead of name split

Use the precomputed sub["url"] to identify which subcategories belong
to a category. Avoids parsing the "Cat > Sub" value string, which would
silently misfire if a category name ever contained " > ".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-05-03 00:26:12 +08:00
parent eeecacc3bd
commit 6bc9d83480

View File

@@ -383,9 +383,10 @@ def build(repo_root: Path) -> None:
seen_subcats: set[tuple[str, str]] = set()
for category in categories:
cat_url_prefix = f"/categories/{category['slug']}/"
for entry in entries:
for sub in entry.get("subcategories", []):
if sub["value"].split(" > ", 1)[0] != category["name"]:
if not sub["url"].startswith(cat_url_prefix):
continue
key = (category["slug"], sub["slug"])
if key in seen_subcats: