{% extends "base.html" %}

{# NOTE: Assumes no pagination #}
{% set CANONICAL_URL = SITEURL + '/' + ARCHIVES_URL %}

{% block title -%}
    Archives &mdash; {{ super() }}
{%- endblock %}

{% block breadcrumbs %}
    {% if DISPLAY_BREADCRUMBS %}
    <ol class="breadcrumb">
        <li><a href="{{ SITE_ROOT_URL | default('/') }}" title="{{ SITENAME }}"><span class="fa fa-home fa-lg"></span></a></li>
        {% if MENUITEMS_2_AT %}
            <li><a href="{{ SITEURL -}} / {{- MENUITEMS_2_AT_LINK }}" title="{{ MENUITEMS_2_AT }}">{{ MENUITEMS_2_AT }}</a></li>
        {% endif %}
        <li class="active">Archives</li>
    </ol>
    {% endif %}
{% endblock %}

{% block content %}
    <section id="content">
        {% block archives_pagetitle %}
            <h1>Archives for {{ SITENAME }}</h1>
        {% endblock %}

        <div id="archives">
            {% block archives_quicklinks %}
                {# Top Row with links to Archives by Year #}
                <div class="row">
                    <div class="archives-quicklinks text-center col-xs-12">
                        {% for article in dates %}
                            {% if loop.index0 == 0 or (article.date.year != dates[loop.index0 - 1].date.year) %}
                                {% if loop.index0 != 0 %} &bull; {% endif -%}
                                <a href=
                                    {%- if YEAR_ARCHIVE_URL -%}
                                        "{{ SITEURL -}} /
                                         {{- article.date.year | datetime_from_period | merge_date_url (YEAR_ARCHIVE_URL) }}"
                                    {%- else -%}
                                        "#{{ article.date.year }}"
                                    {%- endif -%}
                                >
                                    {{- article.date.year -}}
                                </a>
                            {%- endif -%}
                        {%- endfor %}
                    </div>
                    <div class="archives-spacer col-xs-12">&nbsp;</div>
                    <div class="archives-spacer col-xs-12">&nbsp;</div>
                </div>
            {% endblock %}

            {# Main Archive Listing #}
            {# "dates" is the article list, sorted by date #}
            {% for article in dates %}
                <div class="row">
                    {% if (loop.index0 == 0) or (article.date.year != dates[loop.index0 - 1].date.year) %}
                        {% if loop.index0 != 0 -%}
                            <div class="archives-spacer col-xs-12">&nbsp;</div>
                            <div class="archives-spacer col-xs-12">&nbsp;</div>
                        {%- endif %}
                        <div class="archives-date archives-year col-xs-4 col-md-2 col-md-offset-2">
                            <a name="{{ article.date.year }}"></a>
                            {{- article.date.year -}}
                        </div>
                        <div class="archives-title col-xs-7 col-sm-6">
                            &nbsp;
                        </div>
                    {% endif %}
                    {% if (loop.index0 == 0) or
                          (article.date.year != dates[loop.index0 - 1].date.year) or
                          ((article.date.year == dates[loop.index0 - 1].date.year) and (article.date.month != dates[loop.index0 - 1].date.month)) %}
                                {% if ((article.date.year == dates[loop.index0 - 1].date.year) and (article.date.month != dates[loop.index0 - 1].date.month)) -%}
                                            <div class="archives-spacer col-xs-12">&nbsp;</div>
                                {%- endif %}
                                <div class="archives-date archives-month col-xs-4 col-md-2 col-md-offset-2">
                                <a name="{{ article.date.year }}-{{ article.date.month }}"></a>
                                    {{- article.date | strftime('%B') -}}
                                </div>
                                <div class="archives-title col-xs-7 col-sm-6">
                                    &nbsp;
                                </div>
                    {% endif %}

                    <div class="archives-date categories-timestamp col-xs-4 col-md-2 col-md-offset-2">
                        {%- if ((loop.index0 != 0) and
                                (article.date.day == dates[loop.index0 - 1].date.day) and
                                (article.date.month == dates[loop.index0 - 1].date.month) and 
                                (article.date.year == dates[loop.index0 - 1].date.year)) %}
                                    &mdash;
                        {% else -%}
                                    <a name="{{ article.date.year }}-{{ article.date.month }}-{{ article.date.day }}"></a>
                                    <time datetime="{{ article.date.isoformat() }}">{{ article.date | strftime('%a %-d') }}</time>
                        {%- endif -%}
                    </div>
                    <div class="archives-title col-xs-7 col-md-6">
                        {% if article.micro %}
                            {{ article.content }}
                            {# &bull;&nbsp;<span class="label label-primary">
                                <a href="{{ SITEURL -}} / {{- article.url }}"><i class="fa fa-link"></i></a>
                            </span> #}
                        {% elif article.tasknote %}
                            {{ article.tasknote_checkbox }} {{ article.title }}
                            &nbsp;<span class="label label-primary">
                                <a href="{{ SITEURL -}} / {{- article.url }}" title="read more"><i class="fa fa-arrow-circle-right"></i>&nbsp;</a>
                            </span>
                        {% else %}
                            <a href="{{ SITEURL -}} / {{- article.url }}">{{ article.title }}</a>
                            {% if article.subtitle %}
                                <br />
                                <span class="archives-subtitle">
                                    {{ article.subtitle }}
                                </span>
                            {% endif %}
                        {% endif %}
                    </div>
                </div>
            {% endfor %}
        </div>
    </section>
{% endblock %}
