From aa6f632ed835deb905056d65511b4353454384c0 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Mon, 26 Oct 2026 10:57:03 +0800 Subject: [PATCH] refactor: share entry rows macro between home and category pages Co-Authored-By: Claude --- website/templates/_entry_rows.html | 133 ++++++++++++++++++++++++++++ website/templates/category.html | 134 +---------------------------- website/templates/index.html | 125 +-------------------------- 3 files changed, 136 insertions(+), 256 deletions(-) create mode 100644 website/templates/_entry_rows.html diff --git a/website/templates/_entry_rows.html b/website/templates/_entry_rows.html new file mode 100644 index 00000000..5629aff2 --- /dev/null +++ b/website/templates/_entry_rows.html @@ -0,0 +1,133 @@ +{% macro entry_rows(entry, index, home=false) %} + {# On section and subcategory pages the group heading already names the row's use case #} + {% set grouped_page = entry_groups and not group_categories %} + {% set section_path = "/categories/" ~ parent_category.slug ~ "/" if parent_category else current_path %} + + {{ index }} + + {{ entry.name }} + {% if entry.subcategories %}{{ entry.subcategories[0].name }}{% + else %}{{ entry.categories[0] if home else category.name }}{% endif %} + + + {% if entry.downloads is not none %}{{ + "{:,}".format(entry.downloads) }}{% elif entry.source_type == + 'Stdlib' %}Stdlib{% elif + entry.bundled %}Bundled{% elif + entry.badge %}{{ entry.badge }}{% + else %}Not on PyPI{% endif %} + + + {% if entry.stars is not none %}{{ "{:,}".format(entry.stars) }}{% + elif entry.source_type %}{{ entry.source_type }}{% else %}—{% endif %} + + + {% if entry.last_commit_at %}{% else %}—{% endif %} + + + {% for subcat in entry.subcategories %} + + {{ subcat.name }} + + {% endfor %} + {% for cat in entry.categories %} + {{ cat }} + {% endfor %} + {% if entry.groups %} + {% set group_url = filter_urls[entry.groups[0]] %} + + {{ entry.groups[0] }} + + {% endif %} + {% if entry.source_type == 'Stdlib' %} + + Stdlib + + {% endif %} + + + + {% if entry.description %} + + + +
{{ entry.description | safe }}
+ + + {% endif %} + + + +
+ {% if entry.also_see %} +
+ Also see: {% for see in entry.also_see %}{{ see.name }}{% if not loop.last %}, {% endif %}{% endfor %} +
+ {% endif %} +
+ {% if entry.owner %}{{ entry.owner }}/{% endif %}{{ entry.url | replace("https://", "") }} + {% if entry.stars is not none %}/{{ + "{:,}".format(entry.stars) }} stars{% endif %} {% if entry.last_commit_at %}/{% endif %} +
+
+ + + +{% endmacro %} diff --git a/website/templates/category.html b/website/templates/category.html index 10fa0bd5..80f3753a 100644 --- a/website/templates/category.html +++ b/website/templates/category.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% from "_projects_table.html" import projects_table %} +{% from "_entry_rows.html" import entry_rows with context %} {% block title %}{{ category_title }}{% endblock %} {% block description %}{{ category_description }}{% endblock %} {% block canonical_url %}{{ category_url }}{% endblock %} @@ -62,139 +63,6 @@ {% endblock %} {% block content %} -{% macro entry_rows(entry, index) %} - {# On section and subcategory pages the group heading already names the row's use case #} - {% set grouped_page = entry_groups and not group_categories %} - {% set section_path = "/categories/" ~ parent_category.slug ~ "/" if parent_category else current_path %} - - {{ index }} - - {{ entry.name }} - {% if entry.subcategories %}{{ entry.subcategories[0].name }}{% - else %}{{ category.name }}{% endif %} - - - {% if entry.downloads is not none %}{{ - "{:,}".format(entry.downloads) }}{% elif entry.source_type == - 'Stdlib' %}Stdlib{% elif - entry.bundled %}Bundled{% elif - entry.badge %}{{ entry.badge }}{% - else %}Not on PyPI{% endif %} - - - {% if entry.stars is not none %}{{ "{:,}".format(entry.stars) }}{% - elif entry.source_type %}{{ entry.source_type }}{% else %}—{% endif %} - - - {% if entry.last_commit_at %}{% else %}—{% endif %} - - - {% for subcat in entry.subcategories %} - - {{ subcat.name }} - - {% endfor %} - {% for cat in entry.categories %} - {{ cat }} - {% endfor %} - {% if entry.groups %} - {% set group_url = filter_urls[entry.groups[0]] %} - - {{ entry.groups[0] }} - - {% endif %} - {% if entry.source_type == 'Stdlib' %} - - Stdlib - - {% endif %} - - - - {% if entry.description %} - - - -
{{ entry.description | safe }}
- - - {% endif %} - - - -
- {% if entry.also_see %} -
- Also see: {% for see in entry.also_see %}{{ see.name }}{% if not loop.last %}, {% endif %}{% endfor %} -
- {% endif %} -
- {% if entry.owner %}{{ entry.owner }}/{% endif %}{{ entry.url | replace("https://", "") }} - {% if entry.stars is not none %}/{{ - "{:,}".format(entry.stars) }} stars{% endif %} {% if entry.last_commit_at %}/{% endif %} -
-
- - - -{% endmacro %} {% include "_sponsor_band.html" %}
diff --git a/website/templates/index.html b/website/templates/index.html index 8d0a4385..35a8235a 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% from "_projects_table.html" import projects_table %} +{% from "_entry_rows.html" import entry_rows with context %} {% block extra_head %} {% endblock %} @@ -71,129 +72,7 @@ {% call projects_table(entries | length, "across " ~ total_categories ~ " categories") %} {% for entry in entries %} - - {{ loop.index }} - - {{ entry.name }} - {% if entry.subcategories %}{{ entry.subcategories[0].name }}{% - else %}{{ entry.categories[0] }}{% endif %} - - - {% if entry.downloads is not none %}{{ - "{:,}".format(entry.downloads) }}{% elif entry.source_type == - 'Stdlib' %}Stdlib{% elif - entry.bundled %}Bundled{% elif - entry.badge %}{{ entry.badge }}{% - else %}Not on PyPI{% endif %} - - - {% if entry.stars is not none %}{{ "{:,}".format(entry.stars) }}{% - elif entry.source_type %}{{ entry.source_type }}{% else %}—{% endif %} - - - {% if entry.last_commit_at %}{% else %}—{% endif %} - - - {% for subcat in entry.subcategories %} - - {{ subcat.name }} - - {% endfor %} {% for cat in entry.categories %} - {{ cat }} - {% endfor %} - - {{ entry.groups[0] }} - - {% if entry.source_type == 'Stdlib' %} - - Stdlib - - {% endif %} - - - - {% if entry.description %} - - - -
{{ entry.description | safe }}
- - - {% endif %} - - - -
- {% if entry.also_see %} -
- Also see: {% for see in entry.also_see %}{{ see.name }}{% if not loop.last %}, {% endif %}{% endfor %} -
- {% endif %} -
- {% if entry.owner %}{{ entry.owner }}/{% endif %}{{ entry.url | replace("https://", "") }} - {% if entry.stars is not none %}/{{ - "{:,}".format(entry.stars) }} stars{% endif %} {% if entry.last_commit_at %}/{% endif %} -
-
- - - + {{ entry_rows(entry, loop.index, home=true) }} {% endfor %} {% endcall %}