Group blog posts by year

We'll see how much I like this.
This commit is contained in:
akp 2025-05-29 19:41:59 +01:00
parent bd290cf04e
commit 0cb0eb7e31
2 changed files with 27 additions and 11 deletions

View file

@ -1,14 +1,30 @@
{# :t posts = list[typedef.AbbreviatedPost]
:t highlightFavourites = bool #}
{% macro postList(posts, highlightFavourites=True) -%}
<ul>
{% for post in posts %}
{% set showFavourite = post.isFavourite and highlightFavourites %}
<li>
<span class="font--tnum text--secondary">{{ post.publishedDate | fmtdate }}</span> {% if showFavourite %}<b class="favourite">{% endif %}<a href="/blog/{{ post.slug }}">{{ post.title }}</a>{% if showFavourite %}</b>{% endif %}
</li>
{% endfor %}
</ul>
:t highlightFavourites = bool
:t splitYears = bool #}
{% macro postList(posts, highlightFavourites=True, splitYears=True) -%}
{% if splitYears %}
{% for year, items in posts|groupby("publishedDate.year")|reverse %}
<h2 id="year-{{ year }}">{{ year }}</h2>
<ul>
{% for post in items %}
{{ postListItem(post, highlightFavourites) }}
{% endfor %}
</ul>
{% endfor %}
{% else %}
<ul>
{% for post in posts %}
{{ postListItem(post, highlightFavourites) }}
{% endfor %}
</ul>
{% endif %}
{%- endmacro %}
{% macro postListItem(post, highlightFavourite) -%}
{% set showFavourite = post.isFavourite and highlightFavourite %}
<li>
<span class="font--tnum text--secondary">{{ post.publishedDate | fmtdate }}</span> {% if showFavourite %}<b class="favourite">{% endif %}<a href="/blog/{{ post.slug }}">{{ post.title }}</a>{% if showFavourite %}</b>{% endif %}
</li>
{%- endmacro %}
{% macro feedHeaders() -%}

View file

@ -10,7 +10,7 @@
<p>{% if tag.description %}{{ tag.description }}{% endif %}</p>
{{ blog.postList(posts, highlightFavourites=False) }}
{{ blog.postList(posts, highlightFavourites=False, splitYears=False) }}
{% endblock %}
{% block aside %}{% endblock %}