feat: optional alternative tags sort order based on posts count

This commit is contained in:
Phil Schumann 2024-06-29 09:07:36 +02:00 committed by welpo
parent 82ecbc1454
commit c685b95f9e
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
4 changed files with 23 additions and 0 deletions

View file

@ -188,6 +188,11 @@ separator = "•"
# Compact: tag_name^n (superscript number)
compact_tags = false
# How tags are sorted in a Tags listing based on templates/tags/list.html.
# "name" for alphabetical, "frequency" for descending count of posts.
# Default: "name".
tag_sorting = "name"
# Invert the order of the site title and page title in the browser tab.
# Example: true => "Blog • ~/tabi", false => "~/tabi • Blog"
invert_title_order = false

View file

@ -225,6 +225,16 @@ Setting `compact_tags = true` will display them as:
[TagName](#) <sup>n</sup>
### Tags Sorting
| Page | Section | `config.toml` | Follows Hierarchy | Requires JavaScript |
|:----:|:-------:|:-------------:|:-----------------:|:-------------------:|
| ❌ | ❌ | ✅ | ❌ | ❌ |
By default, the [tags page](/tags) sorts tags alphabetically, given the default setting of `tag_sorting = "name"`.
Setting `tag_sorting = "frequency"` will sort them by number-of-posts (descending).
---
## Git Repository Integration

View file

@ -7,6 +7,9 @@
{{ macros_page_header::page_header(title=title)}}
{% set tag_count = terms | length %}
{% if config.extra.tag_sorting == "frequency" %}
{% set terms = terms | sort(attribute="pages") | reverse %}
{% endif %}
<div id="tag-cloud" class="{% if tag_count > 16 %}three-columns{% elif tag_count > 8 %}two-columns{% endif %}">
<ul class="tags">
{%- for term in terms -%}

View file

@ -146,6 +146,11 @@ separator = "•"
# Compact: tag_name^n (superscript number)
compact_tags = false
# How tags are sorted in a Tags listing based on templates/tags/list.html.
# "name" for alphabetical, "frequency" for descending count of posts.
# Default: "name".
tag_sorting = "name"
# Invert the order of the site title and page title in the browser tab.
# Example: true => "Blog • ~/tabi", false => "~/tabi • Blog"
invert_title_order = false