redesign pin and enable pinning only in section.html

This commit is contained in:
welpo 2024-11-13 16:12:56 +01:00
parent e7d64c2b8c
commit 48bfa5c5de
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
15 changed files with 58 additions and 53 deletions

View file

@ -3,24 +3,29 @@
{# 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="") %}
{% 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 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 = [] %}
{% 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 %}
<div class="bloglist-container">
{# Display all posts (pinned first, then regular) #}
{% set all_posts = pinned_posts | concat(with=regular_posts) %}
{% for post in all_posts %}
{% if loop.index <= max %}
{% if loop.index == max or loop.last %}
@ -59,16 +64,6 @@
{%- set show_date = post.date and post_listing_date == "date" or post.date and post_listing_date == "both" or post.date and post_listing_date == "updated" and not post.updated -%}
{%- set show_updated = post.updated and post_listing_date == "updated" or post.updated and post_listing_date == "both" -%}
{% if post.extra.pinned %}
<li class="pinned-label">
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M10.5 2.255v-.01c.003-.03.013-.157-.361-.35C9.703 1.668 8.967 1.5 8 1.5s-1.703.169-2.138.394c-.375.194-.365.32-.362.351v.01c-.003.03-.013.157.362.35C6.297 2.832 7.033 3 8 3s1.703-.169 2.139-.394c.374-.194.364-.32.361-.351M12 2.25c0 .738-.433 1.294-1.136 1.669l.825 2.31c1.553.48 2.561 1.32 2.561 2.52c0 1.854-2.402 2.848-5.5 2.985V15a.75.75 0 0 1-1.5 0v-3.266c-3.098-.136-5.5-1.131-5.5-2.984c0-1.2 1.008-2.04 2.561-2.52l.825-2.311C4.433 3.544 4 2.988 4 2.25C4 .75 5.79 0 8 0s4 .75 4 2.25" clip-rule="evenodd"/></svg>
<span>{{ macros_translate::translate(key="pinned", default="Pinned", language_strings=language_strings) }}</span>
</li>
{%- if show_date -%}
<li class="mobile-only">{{- separator -}}</li>
{%- endif -%}
{% endif %}
{%- if show_date or show_updated -%}
{%- if show_date -%}
<li class="date">{{- macros_format_date::format_date(date=post.date, short=false, language_strings=language_strings) -}}</li>
@ -93,6 +88,13 @@
<section class="bloglist-content {% if bottom_divider -%}bottom-divider{%- endif -%}">
<div>
{% if pinned_first and post.extra.pinned %}
<div class="pinned-label">
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M10.5 2.255v-.01c.003-.03.013-.157-.361-.35C9.703 1.668 8.967 1.5 8 1.5s-1.703.169-2.138.394c-.375.194-.365.32-.362.351v.01c-.003.03-.013.157.362.35C6.297 2.832 7.033 3 8 3s1.703-.169 2.139-.394c.374-.194.364-.32.361-.351M12 2.25c0 .738-.433 1.294-1.136 1.669l.825 2.31c1.553.48 2.561 1.32 2.561 2.52c0 1.854-2.402 2.848-5.5 2.985V15a.75.75 0 0 1-1.5 0v-3.266c-3.098-.136-5.5-1.131-5.5-2.984c0-1.2 1.008-2.04 2.561-2.52l.825-2.311C4.433 3.544 4 2.988 4 2.25C4 .75 5.79 0 8 0s4 .75 4 2.25" clip-rule="evenodd"/></svg>
<span>{{ macros_translate::translate(key="pinned", default="Pinned", language_strings=language_strings) }}</span>
</div>
{% endif %}
<h2 class="bloglist-title">
<a href="{{ post.permalink }}">{{ post.title }}</a>
</h2>

View file

@ -37,7 +37,7 @@
{% endif -%}
{% set max_posts = section.extra.max_posts | default(value=999999) %}
{{ macros_list_posts::list_posts(posts=pages, max=max_posts, language_strings=language_strings, section_path=path) }}
{{ macros_list_posts::list_posts(posts=pages, max=max_posts, language_strings=language_strings, section_path=path, pinned_first=true) }}
</div>
{% if paginator and paginator.pages | length > 0 %}