{# `metadata` can be "dates", "indexes" or both (e.g. "dates indexes" or "indexes dates"). #} {# If both, the order doesn't matter and indexes will always be displayed before dates. #} {# It would also work with arrays (e.g. ["dates"] or ["indexes"] or even ["indexes","dates"]). #} {# Nevertheless, arrays cannot be used as a default value for a macro parameter in Tera (see https://github.com/Keats/tera/issues/710). #} {# `paginator` is only used to compute indexes metadata and can be let empty otherwise. #} {% macro list_posts(posts, max, metadata="dates", language_strings="", section_path="blog", paginator="", pinned_first=false) %} {%- set separator = config.extra.separator | default(value="•") -%} {# Separate pinned and regular posts #} {% set all_posts = [] %} {% if pinned_first %} {% set pinned_posts = [] %} {% set regular_posts = [] %} {% for post in posts %} {% if post.extra.pinned %} {% set_global pinned_posts = pinned_posts | concat(with=post) %} {% else %} {% set_global regular_posts = regular_posts | concat(with=post) %} {% endif %} {% endfor %} {% set all_posts = pinned_posts | concat(with=regular_posts) %} {% else %} {% set all_posts = posts %} {% endif %}
{# Display all posts (pinned first, then regular) #} {% for post in all_posts %} {% if loop.index <= max %} {% if loop.index == max or loop.last %} {% set bottom_divider = false %} {% else %} {% set bottom_divider = true %} {% endif %}
{% if pinned_first and post.extra.pinned %}
{{ macros_translate::translate(key="pinned", default="Pinned", language_strings=language_strings) }}
{% endif %}

{{ post.title }}

{% if post.taxonomies.tags %}
{% for tag in post.taxonomies.tags %} {{ tag }} {% endfor %}
{% endif %}
{% if post.description %}

{{ post.description }}

{% elif post.summary %}

{{ post.summary | striptags | trim_end_matches(pat=".") | safe }}…

{% endif %}
{{ macros_translate::translate(key="read_more", default="Read more", language_strings=language_strings) }} 
{% endif %} {% if not loop.last %} {% if loop.index == max %}
{{ macros_translate::translate(key="all_posts", default="All posts", language_strings=language_strings) }} 
{% endif %} {% endif %} {% endfor %}
{% endmacro %}