blog-source/themes/next/layout/_macro/post-collapse.swig
2022-03-15 20:46:31 +08:00

42 lines
1.3 KiB
Plaintext

{% macro render(posts) %}
{%- set current_year = '1970' %}
{%- for post in posts.toArray() %}
{%- set year = date(post.date, 'YYYY') %}
{%- if year !== current_year %}
{%- set current_year = year %}
<div class="collection-year">
<span class="collection-header">{{ current_year }}</span>
</div>
{%- endif %}
<article itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<div class="post-meta">
<time itemprop="dateCreated"
datetime="{{ moment(post.date).format() }}"
content="{{ date(post.date, config.date_format) }}">
{{ date(post.date, 'MM-DD') }}
</time>
</div>
<div class="post-title">
{%- if post.link %}{# Link posts #}
{%- set postTitleIcon = '<i class="fa fa-external-link-alt"></i>' %}
{%- set postText = post.title or post.link %}
{{ next_url(post.link, postText + postTitleIcon, {class: 'post-title-link post-title-link-external', itemprop: 'url'}) }}
{% else %}
<a class="post-title-link" href="{{ url_for(post.path) }}" itemprop="url">
<span itemprop="name">{{ post.title or __('post.untitled') }}</span>
</a>
{%- endif %}
</div>
</header>
</article>
{%- endfor %}
{% endmacro %}