From 2c8a21d558f5f6b3a208a3caf9a88b01c92ca0e1 Mon Sep 17 00:00:00 2001 From: welpo Date: Thu, 11 Jan 2024 20:14:17 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(archive):=20group=20multi-so?= =?UTF-8?q?urced=20posts=20by=20year?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #251. --- templates/archive.html | 45 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/templates/archive.html b/templates/archive.html index 46b9348..0bf581a 100644 --- a/templates/archive.html +++ b/templates/archive.html @@ -25,24 +25,33 @@ {%- set_global all_posts = all_posts | concat(with=section_item.pages) -%} {%- endfor %} - {% for year, posts in all_posts | group_by(attribute="year") %} - {% if posts | length > 0 %} -
  • -

    {{ year }}

    - -
  • - {% endif %} + {# Group posts by year. #} + {% set posts_by_year = all_posts | group_by(attribute="year") %} + {% set years = [] %} + {% for year, ignored in posts_by_year %} + {% set_global years = years | concat(with=[year]) %} + {% endfor %} + + {# Iterate over sorted & reversed years (newest to oldest). #} + {% for year in years | sort | reverse %} + {% set posts = posts_by_year[year] %} + {% if posts | length > 0 %} +
  • +

    {{ year }}

    + +
  • + {% endif %} {% endfor %}