From 3d3f62cf2009e5612121cece2f17bb2e2abc676a Mon Sep 17 00:00:00 2001 From: Phil Schumann Date: Sat, 29 Jun 2024 17:39:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20allow=20sorting=20tags=20ba?= =?UTF-8?q?sed=20on=20post=20count=20(#344)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: welpo --- config.toml | 5 +++++ content/blog/mastering-tabi-settings/index.ca.md | 11 ++++++++++- content/blog/mastering-tabi-settings/index.es.md | 9 +++++++++ content/blog/mastering-tabi-settings/index.md | 10 ++++++++++ templates/tags/list.html | 5 +++++ templates/taxonomy_list.html | 5 +++++ theme.toml | 5 +++++ 7 files changed, 49 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index 354908e..d77c9ac 100644 --- a/config.toml +++ b/config.toml @@ -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 diff --git a/content/blog/mastering-tabi-settings/index.ca.md b/content/blog/mastering-tabi-settings/index.ca.md index 2641631..70fd7c6 100644 --- a/content/blog/mastering-tabi-settings/index.ca.md +++ b/content/blog/mastering-tabi-settings/index.ca.md @@ -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](#) n +### 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 diff --git a/content/blog/mastering-tabi-settings/index.es.md b/content/blog/mastering-tabi-settings/index.es.md index 451c7a3..2695d7f 100644 --- a/content/blog/mastering-tabi-settings/index.es.md +++ b/content/blog/mastering-tabi-settings/index.es.md @@ -237,6 +237,15 @@ Establecer `compact_tags = true` mostrará las mismas de este modo: [NombreEtiqueta](#) n +### 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 diff --git a/content/blog/mastering-tabi-settings/index.md b/content/blog/mastering-tabi-settings/index.md index c46f5a1..319a8b1 100644 --- a/content/blog/mastering-tabi-settings/index.md +++ b/content/blog/mastering-tabi-settings/index.md @@ -237,6 +237,16 @@ Setting `compact_tags = true` will display them as: [TagName](#) n +### 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 diff --git a/templates/tags/list.html b/templates/tags/list.html index 4aaaeba..7b5e468 100644 --- a/templates/tags/list.html +++ b/templates/tags/list.html @@ -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 %}
    {%- for term in terms -%} diff --git a/templates/taxonomy_list.html b/templates/taxonomy_list.html index 73601d7..b13e1b9 100644 --- a/templates/taxonomy_list.html +++ b/templates/taxonomy_list.html @@ -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 %}
      {%- for term in terms -%} diff --git a/theme.toml b/theme.toml index f086690..12cf60c 100644 --- a/theme.toml +++ b/theme.toml @@ -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