feat(website): embed filter-to-url map in index for client routing

Adds filter_urls dict (categories, groups, subcategories) in build.py,
passes filter_urls_json to the template, and injects a JSON script block
before the results section in index.html. Covered by a new test that
verifies all three URL types are present and correctly resolved.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen 2026-05-03 00:36:41 +08:00
parent e320ba7278
commit e0e7fc9168
No known key found for this signature in database
GPG key ID: B93DE4F003C33630
3 changed files with 51 additions and 0 deletions

View file

@ -315,6 +315,15 @@ def build(repo_root: Path) -> None:
entries = sort_entries(entries)
category_urls = {cat["name"]: category_path(cat) for cat in categories}
filter_urls: dict[str, str] = {}
for cat in categories:
filter_urls[cat["name"]] = category_path(cat)
for group in parsed_groups:
filter_urls[group["name"]] = f"/categories/{group['slug']}/"
for entry in entries:
for sub in entry.get("subcategories", []):
filter_urls[sub["value"]] = sub["url"]
env = Environment(
loader=FileSystemLoader(website / "templates"),
autoescape=True,
@ -339,6 +348,7 @@ def build(repo_root: Path) -> None:
build_date=build_date.strftime("%B %d, %Y"),
sponsors=sponsors,
category_urls=category_urls,
filter_urls_json=json.dumps(filter_urls, sort_keys=True),
),
encoding="utf-8",
)