mirror of
https://github.com/vinta/awesome-python.git
synced 2026-05-10 08:28:40 +08:00
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:
+2
-1
@@ -383,9 +383,10 @@ def build(repo_root: Path) -> None:
|
|||||||
|
|
||||||
seen_subcats: set[tuple[str, str]] = set()
|
seen_subcats: set[tuple[str, str]] = set()
|
||||||
for category in categories:
|
for category in categories:
|
||||||
|
cat_url_prefix = f"/categories/{category['slug']}/"
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
for sub in entry.get("subcategories", []):
|
for sub in entry.get("subcategories", []):
|
||||||
if sub["value"].split(" > ", 1)[0] != category["name"]:
|
if not sub["url"].startswith(cat_url_prefix):
|
||||||
continue
|
continue
|
||||||
key = (category["slug"], sub["slug"])
|
key = (category["slug"], sub["slug"])
|
||||||
if key in seen_subcats:
|
if key in seen_subcats:
|
||||||
|
|||||||
Reference in New Issue
Block a user