feat: allow sorting tags based on post count (#344)

Co-authored-by: welpo <welpo@users.noreply.github.com>
main
Phil Schumann 8 months ago committed by GitHub
parent a907f56bd5
commit 3d3f62cf20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -192,6 +192,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

@ -229,7 +229,7 @@ Aquesta variable accepta qualsevol color CSS vàlid, així que pots utilitzar pa
|:------:|:------:|:-------------:|:-----------------:|:--------------------:|
| ❌ | ❌ | ✅ | ❌ | ❌ |
Per defecte, la [pàgina d'etiquetes](/tags) mostra les etiquetes com:
Per defecte, la [pàgina d'etiquetes](/ca/tags) mostra les etiquetes com:
[NomEtiqueta](#) — n entrada[es]
@ -237,6 +237,15 @@ Establir `compact_tags = true` les mostrarà com:
[NomEtiqueta](#) <sup>n</sup>
### Ordre de les etiquetes
| Pàgina | Secció | `config.toml` | Segueix la jerarquia | Requereix JavaScript |
|:------:|:------:|:-------------:|:-----------------:|:--------------------:|
| ❌ | ❌ | ✅ | ❌ | ❌ |
Per defecte, la [pàgina d'etiquetes](/ca/tags) ordena les etiquetes alfabèticament, donada la configuració predeterminada de `tag_sorting = "name"`.
Si configures `tag_sorting = "frequency"`, s'ordenaran segons el nombre de publicacions (de més a menys).
---
## Integració amb repositoris Git

@ -237,6 +237,15 @@ Establecer `compact_tags = true` mostrará las mismas de este modo:
[NombreEtiqueta](#) <sup>n</sup>
### Orden de las etiquetas
| Página | Sección | `config.toml` | Sigue la jerarquía | Requiere JavaScript |
|:------:|:-------:|:-------------:|:---------------:|:-------------------:|
| ❌ | ❌ | ✅ | ❌ | ❌ |
Por defecto, la [página de etiquetas](/es/tags) ordena las etiquetas alfabéticamente, dada la configuración predeterminada de `tag_sorting = "name"`.
Si configuras `tag_sorting = "frequency"`, se ordenarán según el número de publicaciones (de mayor a menor).
---
## Integración con repositorios Git

@ -237,6 +237,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

@ -7,6 +7,11 @@
{{ 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 %}
{% elif config.extra.tag_sorting != "name" %}
{{ throw (message="Invalid tag_sorting option: " ~ config.extra.tag_sorting ~ ". Valid options are 'name' and 'frequency'.") }}
{% 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 -%}

@ -7,6 +7,11 @@
{{ 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 %}
{% elif config.extra.tag_sorting != "name" %}
{{ throw (message="Invalid tag_sorting option: " ~ config.extra.tag_sorting ~ ". Valid options are 'name' and 'frequency'.") }}
{% 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 -%}

@ -150,6 +150,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

Loading…
Cancel
Save