Skip to content

Commit

Permalink
✨ feat: allow sorting tags based on post count
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Schumann <[email protected]>
  • Loading branch information
welpo and metaleap committed Jun 29, 2024
1 parent fcc3f09 commit da92606
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions content/blog/mastering-tabi-settings/index.ca.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Domina la configuració de tabi: guia completa"
date = 2023-09-18
updated = 2024-06-28
updated = 2024-06-29
description = "Descobreix les múltiples maneres en què pots personalitzar tabi."

[taxonomies]
Expand Down Expand Up @@ -229,14 +229,23 @@ 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]

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
Expand Down
11 changes: 10 additions & 1 deletion content/blog/mastering-tabi-settings/index.es.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Domina la configuración de tabi: guía completa"
date = 2023-09-18
updated = 2024-06-28
updated = 2024-06-29
description = "Descubre las múltiples maneras en que puedes personalizar tabi."

[taxonomies]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion content/blog/mastering-tabi-settings/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
title = "Mastering tabi Settings: A Comprehensive Guide"
date = 2023-09-18
updated = 2024-06-28
updated = 2024-06-29
description = "Discover the many ways you can customise your tabi site."

[taxonomies]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions templates/tags/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
5 changes: 5 additions & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da92606

Please sign in to comment.