{% extends "base.html" %}

{# Group template - used for tags index, authors index, archive index, etc. #}
{# This template shows a list of groups (tags, authors, years) and their content counts #}

{% block main %}

{# Page Title #}
<header class="group-header">
    <h1 class="group-title">{{ title }}</h1>
</header>

{# Group Listing with IndieWeb h-feed #}
<section class="groups-list h-feed">
    <h1 class="p-name" style="display: none;">{{ title }}</h1>

    {% for name, items in group(kind=kind) %}
    {% if kind == "stream" and name == "draft" %}{% continue %}{% endif %}
    <div class="group-item">
        <h2 class="group-name">
            {% set slug = name | trim | slugify %}
            {% if kind != "stream" %}
            {% set slug = kind ~ "-" ~ slug %}
            {% endif %}
            {% set link = slug ~ ".html"%}
            <a href="{{url_for(path=link)}}">{%if kind == "author" %}{% include "group_author_avatar.html" ignore missing%}{% endif %}{% if kind == "stream" %}{{ stream_display_name(stream=name) }}{% elif kind == "series" %}{{ series_display_name(series=name) }}{% else %}{{name}}{% endif %}</a>
        </h2>
        <span class="group-count">{{ items | remove_draft | length }} post{% if items | remove_draft | length != 1 %}s{% endif %}</span>
        <div class="group-preview">
            {# Show preview of recent posts in this tag with IndieWeb h-entry #}
            {% for post in items | remove_draft | sort(attribute="date") | reverse %}
            <div class="group-preview-item h-entry">
                <a href="{{url_for(path=post.slug ~ '.html')}}" class="group-preview-link u-url p-name">{{ post.title }}</a>
                {% if post.date %}
                <small class="group-preview-date"><time class="dt-published" datetime="{{ post.date | date(format='%+') }}">{{ post.date | date(format='%B %Y') }}</time></small>
                {% endif %}
            </div>
            {% endfor %}
        </div>
    </div>
    {% endfor %}
</section>

{# Back to main navigation #}
<nav class="group-navigation">
    <a href="{{url_for(path='index.html')}}" class="nav-link">← Back to Home</a>
</nav>

{% endblock %}
