Skip to content

Commit

Permalink
✨ feat: allow sorting tags based on post count (#344)
Browse files Browse the repository at this point in the history
Co-authored-by: welpo <[email protected]>
  • Loading branch information
metaleap and welpo authored Jun 29, 2024
1 parent a907f56 commit 3d3f62c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
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
11 changes: 10 additions & 1 deletion content/blog/mastering-tabi-settings/index.ca.md
Original file line number Diff line number Diff line change
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
9 changes: 9 additions & 0 deletions content/blog/mastering-tabi-settings/index.es.md
Original file line number Diff line number Diff line change
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
10 changes: 10 additions & 0 deletions content/blog/mastering-tabi-settings/index.md
Original file line number Diff line number Diff line change
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 templates/taxonomy_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 3d3f62c

Please sign in to comment.