{% extends "base.html" %}
{# this is the actual, per article ("post") page #}

{% if not article.disable_canonical_url %}
    {% set CANONICAL_URL = SITEURL + '/' + article.url %}
s{% endif %}

{% block title -%}
    {{ article.title | striptags | breaking_spaces }} &mdash; {{ super() }}
{%- endblock %}

{% block html_lang %}{{ article.lang }}{% endblock %}

{% block meta %}
    {% if article.author %}
        <meta name="author" content="{{ article.author }}">
    {% else %}
        <meta name="author" content="{{ AUTHOR }}">
    {% endif %}
    {% if article.tags %}
        <meta name="keywords" content="{{ article.tags | join(',') | striptags }}">
    {% endif %}
    {% if article.summary %}
        <meta name="description" content="{{ article.summary | striptags | escape }}">
    {% endif %}
{% endblock %}

{#
{% block opengraph %}
    {% if OPEN_GRAPH_FB_APP_ID %}
        <meta property="fb:app_id" content="{{ OPEN_GRAPH_FB_APP_ID }}">
        <meta property="og:site_name" content="{{ SITENAME }}">
        <meta property="og:type" content="article">
        <meta property="og:title" content="{{ article.title | striptags | escape | breaking_spaces }}">
        <meta property="og:url" content="{{ SITEURL -}} / {{- article.url }}">
        <meta property="og:description" content="{{ article.summary | striptags | escape }}">
        <meta property="article:published_time" content="{{ article.date.strftime('%Y-%m-%d') }}">
        {% if article.category %}
            <meta property="article:section" content="{{ article.category }}">
        {% endif %}
        {% for tag in article.tags %}
            <meta property="article:tag" content="{{ tag }}">
        {% endfor %}
        {% if article.author %}
            <meta property="article:author" content="{{ article.author }}">
        {% elif AUTHOR %}
            <meta property="article:author" content="{{ AUTHOR }}">
        {% endif %}
        {% if article.og_image %}
            <meta property="og:image"
                  content="{{ SITEURL -}} / {{- article.og_image }}">
        {% elif OPEN_GRAPH_IMAGE %}
            <meta property="og:image"
                  content="{{ SITEURL -}} / {{- OPEN_GRAPH_IMAGE }}">
        {% endif %}
    {% endif %}
{% endblock %}
#}

{% block canonical_rel %}
    {% if article.redirect_url %}
        <link rel="canonical" href="{{ article.redirect_url }}">
    {% else %}
        <link rel="canonical" href="{{ SITEURL -}} / {{- article.url }}">
    {% endif %}
{% endblock %}

{% block head_redirect %}
    {% if article.redirect_url %}
        {# In-content manual link is added in the article.html template #}
        <link rel="canonical" href="{{ article.redirect_url }}">
        <meta http-equiv="refresh" content="0;url={{ article.redirect_url }}">
    {% endif %}
{% 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 %}
            {% if DISPLAY_CATEGORY_IN_BREADCRUMBS or article.micro %}
                <li><a href="{{ SITEURL -}} / {{- article.category.url }}" title="{{ article.category | striptags | trim }}">{{ article.category | striptags | trim }}</a></li>
            {% endif %}
            {% if article.micro %}
                <li class="active">{{ article.date | datetime("%B %d, %Y at %H:%M") }}</li>
            {% else %}
                <li class="active">{{ article.title | striptags | trim }}</li>
            {% endif %}
        </ol>     
    {% endif %}
{% endblock %}

{% block content %}
    <section id="content">
        <article>
            {% if article.image %}
                <img class="featured-image image-process-article-feature" src="{{ SITEURL -}} / {{- article.image | urlencode }}" alt="{{ article.title | striptags }}">
            {% elif article.gpx %}
                <img class="featured-image" src="{{ SITEURL -}} / {{- article.gpx_default_image | urlencode }}" alt="{{ article.title | striptags }}">
            {% elif CATEGORY_IMAGES and article.category in CATEGORY_IMAGES %}
                <img class="featured-image image-process-article-feature" src="{{ SITEURL -}} / {{- CATEGORY_IMAGES[article.category] | urlencode }}" alt="{{ article.category | striptags }}">
            {% endif %}

            {% if article.micro %}
                {# pass #}
            {% elif article.tasknote and TASKNOTES_DEV_URL and TASKNOTES_VERSION %}
            {# i.e. only if the TaskNote plugin is active #}
            <header class="entry-header">
                <p>
                    {{ article.summary }}
                </p>
            </header>
            {% else %}
            <header class="entry-header">
                <h1>
                    <a href="{{ SITEURL -}} / {{- article.url }}"
                       rel="bookmark"
                       title="Permalink to {{ article.title | striptags }}">
                        {{ article.title|replace('&nbsp;', ' ') }}
                    </a>
                </h1>

                {% if article.subtitle %}
                    <p class="article-subtitle">
                        {{ article.subtitle }}
                    </p>
                {% endif %}
            </header>  <!-- /.entry-header -->
            {% endif %}

            <div class="entry-content">
                {% if article.tasknote and TASKNOTES_DEV_URL and TASKNOTES_VERSION %}
                    {# pass #}
                    <!-- no "article_info" panel for tasknotes -->
                {% else %}
                    <div class="panel">
                        <div class="panel-body">
                            {% include "includes/article_info.html" %}
                        </div>
                    </div>
                {% endif %}
    
                {% if article.gpx %}
                    {# for a GPX "Article", the "content" is the raw GPX file #}
                {% else %}
                    {{ article.content }}
                {% endif %}

                {% if article.redirect_url %}
                    {# meta tag for redirect is in base.html template #}
                    <p>If you are not redirected, please click here:<br>
                    <a href="{{ article.redirect_url }}">{{ article.redirect_url }}</a></p>
                {% endif %}
            </div>  <!-- /.entry-content -->
            {% include 'includes/neighbors.html' %}
            {% include 'includes/related-posts.html' %}
            {% include 'includes/comments.html' %}
        </article>
    </section>  <!-- /#content -->
{% endblock %}

{% block additional_template_debug %}
    <p><b>Article</b>: {{ article }} <br />
        <ul>
            <li><b>source_path</b>: {{ article.source_path }} </li>

            <li><b>title</b>: {{ article.title }} </li>
            <li><b>lang</b>: {{ article.lang }} </li>
            <li><b>author</b>: {{ article.author }} </li>
            <li><b>summary</b>: {{ article.summary }} </li>
            <li><b>tags</b>: {{ article.tags }} </li>
            <li><b>date</b>: {{ article.date }} </li>
            <li><b>og_image</b>: {{ article.og_image }} </li>
            <li><b>url</b>: {{ article.url }} </li>
            <li><b>redirect_url</b>: {{ article.redirect_url }} </li>
            <li><b>category</b>: {{ article.category }} </li>
            <li><b>image</b>: {{ article.image }} </li>
            <li><b>micro</b>: {{ article.micro }} </li>
            <li><b>tasknote</b>: {{ article.tasknote }} </li>
            <li><b>subtitle</b>: {{ article.subtitle }} </li>
            <li><b>gpx</b>: {{ article.gpx }} </li>
            <li><b>template</b>: {{ article.template }} </li>

            <li><b>metadata</b>:
            <ul>
            {% for key, value in article.metadata.items() %}
                <li>{{ key }} : {{ value }} </li>
            {% endfor %}
            </ul></li>
            {# article.content #}
            {# article.settings #}
            {# article.context #}
        </ul>
    </p>
{% endblock %}
