{% extends 'base.html' %}

{% block title %}
{{ article.title|striptags|e }} {% if article.subtitle %} - {{ article.subtitle|striptags|e }} {% endif %} · {{ super() }}
{% endblock title %}

{% block head_description %}
{% if article.summary %}
{{ article.summary|striptags|e }}
{% endif %}
{% endblock head_description %}

{% block meta_tags_in_head %}
{% if article.redirect %}
<meta http-equiv="refresh" content="0;URL={{ article.redirect }}" />
{% endif %}
{{ super() }}
{% if article.tags or article.category or article.keywords %}
<meta name="keywords" content="{{ [article.tags|join(', '), article.category, article.keywords]|join(', ') }}" />
{% endif %}

{% from '_includes/smo_metadata.html' import smo_metadata with context %}
{{ smo_metadata(article) }}
{% endblock meta_tags_in_head %}

{% block head_links %}
{{ super() }}
{% include '_includes/photos_header.html' %}
{% endblock head_links %}

{% block content %}
<article itemscope>
<div class="row-fluid">
    <header class="page-header span10 offset2">
        <h1>
            <a href="{{ SITEURL }}/{{ article.url }}">
                {{ article.title }}
                {% if article.subtitle %}
                <small class="subtitle">
                    {{ article.subtitle }}
                </small>
                {% endif %}
            </a>
        </h1>
    </header>
</div>

<div class="row-fluid">
    {% if article.toc %}
    <div class="span2 table-of-content">
        <nav>
        {{ article.toc }}
        </nav>
    </div>
    <div class="span8 article-content">
       {% else %}
        <div class="span8 offset2 article-content">
            {% endif %}
            {% import '_includes/translations.html' as translations with context %}
            {{ translations.translations_for(article) }}
            {{ article.content }}

            {% if article.photo_gallery %}
            <div class="gallery">
                {% for title, gallery in article.photo_gallery %}
                <h1>{{ title }}</h1>
                {% for name, photo, thumb, exif, caption in gallery %}
                <a href="{{ SITEURL }}/{{ photo }}" title="{{ name }}" exif="{{ exif }}" caption="{{ caption }}"><img
                        src="{{ SITEURL }}/{{ thumb }}"></a>
                {% endfor %}
                {% endfor %}
            </div>
            {% endif %}

            {% from '_includes/applause_button.html' import applause_button with context %}
            {{ applause_button(article) }}
            {% from '_includes/share_links.html' import share_links with context %}
            {{ share_links(article) }}
            {% from '_includes/article_author.html' import article_author with context %}
            {{ article_author(article) }}
            {% from '_includes/comments.html' import comments_section with context %}
            {{ comments_section(article) }}
            <hr/>
            {% include '_includes/related_posts.html' with context %}
            {% if article.prev_article or article.next_article %}
            <aside>
            <nav>
            <ul class="articles-timeline">
                {% if article.prev_article %}
                    {% set ptitle = article.prev_article.title|striptags|e %}
                    {% set pv_title = article.prev_article.title|striptags %}
                    {% if article.prev_article.subtitle %}
                    {% set pv_title = pv_title + ' ' +  '<small class="subtitle">' + article.prev_article.subtitle|striptags + '</small>' %}
                        {% set ptitle = ptitle + ' - ' + article.prev_article.subtitle|e %}
                    {% endif %}
                <li class="previous-article">« <a href="{{ SITEURL }}/{{ article.prev_article.url }}" title="Previous: {{ ptitle }}">{{ pv_title }}</a></li>
                {% endif %}
                {% if article.next_article %}
                    {% set ntitle = article.next_article.title|striptags|e %}
                    {% set nv_title = article.next_article.title|striptags %}
                    {% if article.next_article.subtitle %}
                    {% set nv_title = nv_title + ' ' +  '<small class="subtitle">' + article.next_article.subtitle|striptags + '</small>' %}
                        {% set ntitle = ntitle + ' - ' + article.next_article.subtitle|e %}
                    {% endif %}
                <li class="next-article"><a href="{{ SITEURL }}/{{ article.next_article.url }}" title="Next: {{ ntitle }}">{{ nv_title }}</a> »</li>
                {% endif %}
            </ul>
            </nav>
            </aside>
            {% endif %}
        </div>
        <section id="article-sidebar" class="span2">
            {% include '_includes/post_stats.html' %}
            {% if article.date %}
            <h4>Published</h4>
            {% set day = article.date.strftime('%d')|int %}
            <time itemprop="dateCreated" datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time>
            {% endif %}
            {% include '_includes/last_updated.html' %}
            {% include '_includes/series.html' %}
            {% if article.category|trim|count > 0 %}
            <h4>Category</h4>
            {% from '_includes/_defaults.html' import CATEGORIES_URL with context %}
            <a class="category-link" href="{{ SITEURL }}/{{ CATEGORIES_URL }}#{{ category.slug }}-ref">{{ article.category }}</a>
            {% endif %}
            {% if article.tags and article.tags[0]|trim|count > 0 %}
            {% from '_includes/_defaults.html' import TAGS_URL with context %}
            <h4>Tags</h4>
            <ul class="list-of-tags tags-in-article">
                {% for tag in article.tags|sort %}
                <li><a href="{{ SITEURL }}/{{ TAGS_URL }}#{{ tag.slug }}-ref">{{ tag }}
                    {% for aTag, tagged_articles in tags if aTag == tag %}
                    <span class="superscript">{{ tagged_articles|count }}</span>
                    {% endfor %}</a></li>
                {% endfor %}
            </ul>
            {% endif %}
            {% include '_includes/social_links.html' %}
            {% from '_includes/mailchimp.html' import mailchimp with context %}
            {{ mailchimp(article) }}
            {% from '_includes/freelists.html' import freelists with context %}
            {{ freelists(article) }}
        </section>
</div>
</article>
{% include '_includes/photoswipe.html' %}
{% endblock content %}

{% block script %}
    {{ super() }}
    {% from '_includes/comments.html' import comments_script with context %}
    {{ comments_script() }}
    {% include '_includes/photos_footer.html' %}
{% endblock script %}
