{% extends "base.html" %}

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

{% block breadcrumbs %}
    {% if DISPLAY_BREADCRUMBS %}
    <ol class="breadcrumb">
        <li><a href="{{ SITE_ROOT_URL }}" 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">
        <h1>Archives for {{ SITENAME }}</h1>

        <div id="archives">
            {# 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="#{{ article.date.year }}">{{ 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>

            {# Main Archive Listing #}
            {% 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 ((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 -%}
                                    <time datetime="{{ article.date.isoformat() }}">{{ article.date | strftime('%a %-d') }}</time>
                        {%- endif -%}
                    </div>
                    <div class="archives-title col-xs-7 col-md-6">
                        <a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a>
                        {% if article.subtitle %}<br />{{ article.subtitle }}{% endif %}
                    </div>
                </div>
            {% endfor %}
        </div>
    </section>
{% endblock %}
