{% extends "base.html" %} {% block title %}{% if archive_title %}{{ archive_title }}{% else %}Archive{% endif %} - {{ site_title }}{% endblock %} {% block meta_tags %} {% from '_listing_meta_tags.html' import listing_meta_tags with context %} {{ listing_meta_tags(archive_title ~ " - " ~ site_title if archive_title else site_title) }} {% endblock %} {% block extra_head %} {% endblock %} {% from '_pagination.html' import pagination %} {% from '_post_summary.html' import post_summary with context %} {% block content %} {% if posts and not archive_title %} {# Main archive page - build year/month structure first for both content and TOC #} {% set ns = namespace(years={}) %} {% for post in posts %} {% if post.date %} {% set year = post.date.year %} {% set month = post.date.month %} {% set month_name = post.date.strftime('%B') %} {% set month_key = '%02d'|format(month) %} {% if year not in ns.years %} {% set _ = ns.years.update({year: {}}) %} {% endif %} {% if month_key not in ns.years[year] %} {% set _ = ns.years[year].update({month_key: {'name': month_name, 'posts': []}}) %} {% endif %} {% set _ = ns.years[year][month_key]['posts'].append(post) %} {% endif %} {% endfor %} {# Pre-compute year post counts for use in both the main content and the TOC #} {% set year_counts = {} %} {% for year in ns.years %} {% set year_count_ns = namespace(count=0) %} {% for month_key in ns.years[year] %} {% set year_count_ns.count = year_count_ns.count + ns.years[year][month_key]['posts']|length %} {% endfor %} {% set _ = year_counts.update({year: year_count_ns.count}) %} {% endfor %} {% set total_post_count = posts|length %}

Archive ({{ total_post_count }} {{ 'post' if total_post_count == 1 else 'posts' }})

{{ pagination(page, total_pages, pagination_page_urls) }} {% for year in ns.years.keys()|sort(reverse=True) %}

{{ year }} ({{ year_counts[year] }} {{ 'post' if year_counts[year] == 1 else 'posts' }})

{% for month_key in ns.years[year].keys()|sort(reverse=True) %} {% set month_count = ns.years[year][month_key]['posts']|length %}

{{ ns.years[year][month_key]['name'] }} ({{ month_count }} {{ 'post' if month_count == 1 else 'posts' }})

{% endfor %}
{% endfor %} {{ pagination(page, total_pages, pagination_page_urls) }}
{% else %}

{% if archive_title %}{{ archive_title }}{% else %}Archive{% endif %}

{{ pagination(page, total_pages, pagination_page_urls) }} {% if posts %} {# Date-based archive pages (year/month) - show full post content #} {% for post in posts %} {{ post_summary(post) }} {% endfor %} {% else %}

No posts yet.

{% endif %} {{ pagination(page, total_pages, pagination_page_urls) }}
{% endif %} {% endblock %}