fix(website): remove duplicate tag on group/category pages

The category template rendered a tag for `category.name` plus a tag for
`entry.groups[0]`, which duplicated the group name on group pages where
those values are identical (e.g. /categories/python-language/ showing
"Python Language" twice). It also never rendered `entry.categories`, so
group pages omitted each project's actual category.

Mirror the index template's tag rendering on category, group, and
subcategory pages, and mark whichever tag matches the current page URL
as active. Pass `category_urls` and `current_path` to each render call
so the template can match by URL.
This commit is contained in:
Vinta Chen
2026-05-03 07:51:39 +08:00
parent b0136ac266
commit 8e00055c8c
2 changed files with 19 additions and 6 deletions

View File

@@ -369,6 +369,8 @@ def build(repo_root: Path) -> None:
entries=category_entries,
total_categories=len(categories),
page_kind="category",
category_urls=category_urls,
current_path=category_path(category),
),
encoding="utf-8",
)
@@ -390,6 +392,8 @@ def build(repo_root: Path) -> None:
entries=group_entries,
total_categories=len(categories),
page_kind="group",
category_urls=category_urls,
current_path=group_path(group["slug"]),
),
encoding="utf-8",
)
@@ -425,6 +429,8 @@ def build(repo_root: Path) -> None:
total_categories=len(categories),
page_kind="subcategory",
parent_category=category,
category_urls=category_urls,
current_path=subcategory_path(category["slug"], sub["slug"]),
),
encoding="utf-8",
)

View File

@@ -117,18 +117,25 @@
</td>
<td class="col-cat">
{% for subcat in entry.subcategories %}
<button class="tag" data-value="{{ subcat.value }}" data-url="{{ subcat.url }}">
<button class="tag{% if subcat.url == current_path %} active{% endif %}" data-value="{{ subcat.value }}" data-url="{{ subcat.url }}">
{{ subcat.name }}
</button>
{% endfor %}
<button class="tag active" data-value="{{ category.name }}" data-url="/categories/{{ category.slug }}/">
{{ category.name }}
</button>
{% for cat in entry.categories %}
<a
class="tag{% if category_urls[cat] == current_path %} active{% endif %}"
href="{{ category_urls[cat] }}"
data-value="{{ cat }}"
data-url="{{ category_urls[cat] }}"
>{{ cat }}</a
>
{% endfor %}
{% if entry.groups %}
{% set group_url = "/categories/" ~ (entry.groups[0] | slugify) ~ "/" %}
<button
class="tag tag-group"
class="tag tag-group{% if group_url == current_path %} active{% endif %}"
data-value="{{ entry.groups[0] }}"
data-url="/categories/{{ entry.groups[0] | slugify }}/"
data-url="{{ group_url }}"
>
{{ entry.groups[0] }}
</button>