refactor(website): extract render_category, replace slugify filter with filter_urls map

- Extract render_category() helper to deduplicate the three category/group/builtin
  rendering blocks in build.py
- Replace synthetic dict literals with synthetic_category() helper
- Rewrite subcategory rendering to avoid O(n²) loop using precomputed dicts
- Pass filter_urls (not just JSON) to templates so Jinja can look up group URLs
  directly instead of applying the slugify filter at render time
- Remove slugify from env.filters (no longer used in templates)
- Replace isIndexPage() wrapper with isIndexDocument constant in main.js
- Fix: call applyFilters() on page load when activeFilter is set
- Remove dead else branch in tag click handler (category pages with no URL)
- Switch .hero-category-links from CSS columns to CSS grid for more even layout
- Remove max-width cap on .category-subtitle

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-05-03 11:38:22 +08:00
parent 8a32d27ef5
commit ee01a0bade
5 changed files with 91 additions and 122 deletions
+2 -2
View File
@@ -24,7 +24,7 @@
</nav>
<div class="category-hero-copy">
{% if page_kind == "subcategory" and parent_category %}
{% if parent_category %}
<p class="category-breadcrumb">
<a href="/categories/{{ parent_category.slug }}/">{{ parent_category.name }}</a>
</p>
@@ -183,7 +183,7 @@
>
{% endfor %}
{% if entry.groups %}
{% set group_url = "/categories/" ~ (entry.groups[0] | slugify) ~ "/" %}
{% set group_url = filter_urls[entry.groups[0]] %}
<button
class="tag tag-group{% if group_url == current_path %} active{% endif %}"
data-value="{{ entry.groups[0] }}"
+1 -1
View File
@@ -235,7 +235,7 @@
<button
class="tag tag-group"
data-value="{{ entry.groups[0] }}"
data-url="/categories/{{ entry.groups[0] | slugify }}/"
data-url="{{ filter_urls[entry.groups[0]] }}"
>
{{ entry.groups[0] }}
</button>