{% extends "base.html" %}
{% block title %}{{ article.title }}{% endblock %}

{% block head %}
    {{ super() }}

    <link href="{{ SITEURL }}/{{ article.url }}" rel="canonical" />
    {% for keyword in article.keywords %}
        <meta name="keywords" content="{{keyword}}" >
    {% endfor %}

    {% if description %}
        <meta name="description" content="{{ description }}">
    {% elif article.headline %}
        <meta name="description" content="{{ article.headline }}">
    {% elif article.summary %}
        <meta name="description" content="{{ article.summary|striptags|truncate(140) }}">
    {% endif %}

    {% for author in article.authors %}
        <meta name="author" content="{{ author }}">
    {% endfor %}

    {% for tag in article.tags %}
        <meta name="tags" content="{{tag}}">
    {% endfor %}
{% endblock %}

{% block twitter_card %}
    {% for name,link in SOCIAL if name.lower() in ['twitter'] %}
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:site" content="@{{ link|replace('http://', 'https://')|replace('https://twitter.com/', '') }}">
        <meta name="twitter:title" content="{{ article.title }}">
        <meta name="twitter:url" content="{{ SITEURL }}/{{ article.url }}">

        {% if article.twitter_image %}
            {% if article.twitter_image|lower|truncate(4, True, '') == "http" %}
                <meta name="twitter:image:src" content="{{ article.twitter_image }}">
            {% else %}
                <meta name="twitter:image:src" content="{{ SITEURL }}/{{ article.twitter_image }}">
            {% endif %}
        {% elif article.header_cover %}
            <meta name="twitter:image:src" content="{{ SITEURL }}/{{ article.header_cover }}">
        {% elif HEADER_COVER %}
            <meta name="twitter:image:src" content="{{ SITEURL }}/{{ HEADER_COVER }}">
        {% else %}
            <meta name="twitter:image:src" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
        {% endif %}

        {% if description %}
            <meta name="twitter:description" content="{{ description }}">
        {% elif article.headline %}
            <meta name="twitter:description" content="{{ article.headline }}">
        {% else %}
            <meta name="twitter:description" content="{{ article.summary|striptags|truncate(140) }}">
        {% endif %}
    {% endfor %}
{% endblock %}
{% block opengraph %}
  {{ super() }}
  <meta property="og:type" content="article">
        {% for author in article.authors %}
            <meta property="article:author" content="{{ SITEURL }}/{{ author.url }}">
        {% endfor %}
  <meta property="og:url" content="{{ SITEURL }}/{{ article.url }}">
  <meta property="og:title" content="{{ article.title }}">
  <meta property="article:published_time" content="{{ article.date }}">
        {% if description %}
            <meta property="og:description" content="{{ description }}">
        {% elif article.headline %}
            <meta property="og:description" content="{{ article.headline }}">
        {% elif article.summary %}
            <meta property="og:description" content="{{ article.summary|striptags|truncate(140) }}">
        {% endif %}

        {% if article.og_image %}
            {% if article.og_image|lower|truncate(4, True, '') == "http" %}
                <meta property="og:image" content="{{ article.og_image }}">
            {% else %}
                <meta property="og:image" content="{{ SITEURL }}/{{ article.og_image }}">
            {% endif %}
        {% elif article.header_cover %}
            <meta property="og:image" content="{{ SITEURL }}/{{ article.header_cover }}">
        {% elif HEADER_COVER %}
            <meta property="og:image" content="{{ SITEURL }}/{{ HEADER_COVER }}">
        {% else %}
            <meta property="og:image" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
        {% endif %}
{% endblock %}

{% block header %}
    <!-- Progressbar -->
    <div class="progress-container">
        <span class="progress-bar"></span>
    </div>

    <!-- Page Header -->
    <!-- Set your background image for this header on the line below. -->
    <header id="post-header" class="has-cover">
      <div class="inner">
        <nav id="navigation">
          {% if SITE_LOGO %}
            <span class="blog-logo">
                <a href="{{ SITEURL }}"><img src="{{SITE_LOGO}}" alt="Blog Logo" /></a>
            </span>
          {% else %}
            <span id="home-button" class="nav-button">
                <a class="home-button" href="{{ SITEURL }}" title="Home"><i class="ic ic-arrow-left"></i> Home</a>
            </span>
          {% endif %}
          <span id="menu-button" class="nav-button">
            <a class="menu-button"><i class="ic ic-menu"></i> Menu</a>
          </span>
        </nav>
        <h1 class="post-title">{{ article.title }}</h1>
        <!-- TODO : Proper class for headline -->
        {% if article.headline %}
            <span class="blog-description">{{ article.headline }}</h3>
        {% endif %}
        <span class="post-meta">
            {% for author in article.authors %}
                <a href="{{ SITEURL }}/{{ author.url }}">{{ author|capitalize }}</a>
            {% endfor %}
            | <time datetime="{{ article.locale_date }}">{{ article.locale_date }}</time>
        </span>
        <!-- TODO : Modified check -->
        {% if article.modified %}
            <span class="post-meta"> | Updated on {{ article.locale_modified }}</span>
        {% endif %}        
        {% if article.header_cover %}
            <div class="post-cover cover" style="background-image: url('{{ article.header_cover }}')">
        {% elif HEADER_COVER %}
            <div class="post-cover cover" style="background-image: url('{{ HEADER_COVER }}')">            
        {% elif HEADER_COLOR %}
            <div class="post-cover cover" style="background-color: {{ HEADER_COLOR }}">
        {% else %}
            <div class="post-cover cover" style="background-image: url('{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg')">
        {% endif %}        
      </div>
    </header>    
{% endblock header %}

{% block content %}

    <!-- Post content -->
    <main class="content" role="main">
        <article class="post">
        <div class="inner">
            <section class="post-content">
                {{article.content}}
            </section>

            <section class="post-info">
                <div class="post-share">
                    <a class="twitter" href="https://twitter.com/share?text={{ article.title }}&amp;url={{ SITEURL }}/{{ article.url }}" onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
                    <i class="ic ic-twitter"></i><span class="hidden">Twitter</span>
                    </a>
                    <a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u={{ SITEURL }}/{{ article.url }}" onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
                    <i class="ic ic-facebook"></i><span class="hidden">Facebook</span>
                    </a>
                    <a class="googleplus" href="https://plus.google.com/share?url={{ SITEURL }}/{{ article.url }}" onclick="window.open(this.href, 'google-plus-share', 'width=490,height=530');return false;">
                    <i class="ic ic-googleplus"></i><span class="hidden">Google+</span>
                    </a>
                    <div class="clear"></div>
                </div>

                {% if article.tags %}
                <aside class="post-tags">
                    {% for tag in article.tags %}<a href="{{ SITEURL }}/{{ tag.url }}">{{ tag | escape }}</a>{% if not loop.last %}{% endif %}{% endfor %}
                </aside>
                {% endif %}

                <div class="clear"></div>

                {% for author in article.authors %}
                {% if AUTHORS_BIO and author.name.lower() in AUTHORS_BIO %}
                <aside class="post-author">
                    {% if AUTHORS_BIO[author.name.lower()].image %}
                        <figure class="post-author-avatar">
                            <img src="{{AUTHORS_BIO[author.name.lower()].image}}" alt="{{author.name | capitalize}}" />
                        </figure>
                    {% endif %}
                    <div class="post-author-bio">
                        <h4 class="post-author-name"><a href="{{ SITEURL }}/{{author.url}}">{{author.name | capitalize}}</a></h4>
                        {% if AUTHORS_BIO[author.name.lower()].bio %}
                            <p class="post-author-about">{{AUTHORS_BIO[author.name.lower()].bio}}</p>
                        {% endif %}
                        {% if AUTHORS_BIO[author.name.lower()].location %}
                            <span class="post-author-location"><i class="ic ic-location"></i> {{AUTHORS_BIO[author.name.lower()].location}}</span>
                        {% endif %}
                        {% if AUTHORS_BIO[author.name.lower()].website %}
                            <span class="post-author-website"><a href="{{AUTHORS_BIO[author.name.lower()].website}}"><i class="ic ic-link"></i> Website</a></span>
                        {% endif %}
                        {% if AUTHORS_BIO[author.name.lower()].twitter %}
                            <span class="post-author-twitter"><a target="_blank" href="https://twitter.com/{{AUTHORS_BIO[author.name.lower()].twitter}}"><i class="ic ic-twitter"></i> Twitter</a></span>
                        {% endif %}
                        {% if AUTHORS_BIO[author.name.lower()].facebook %}
                            <span class="post-author-facebook"><a target="_blank" href="https://facebook.com/{{AUTHORS_BIO[author.name.lower()].facebook}}"><i class="ic ic-facebook"></i> Facebook</a></span>
                        {% endif %}
                    </div>
                    <div class="clear"></div>
                </aside>
                {% endif %} 
                {% endfor %}

                </section>

                {% if DISQUS_SITENAME and SITEURL and article.status != "draft" %}
                <script type="text/javascript">
                    var disqus = '{{ DISQUS_SITENAME }}';
                    var disqus_shortname = '{{ DISQUS_SITENAME }}';
                    {% if article.disqus_identifier %}
                    var disqus_identifier = '{{ article.disqus_identifier }}';
                    {% else %}
                    var disqus_identifier = '/{{ article.url }}';
                    {% endif %}
                    var disqus_url = '{{ SITEURL }}/{{ article.url }}';
                </script>
                <noscript>Please enable JavaScript to view the comments.</noscript>                  
                <section class="post-comments">
                    {% if article.disqus_identifier %}
                        <a id="show-disqus" class="post-comments-activate" data-disqus-identifier="{{ article.disqus_identifier }}" >Show Comments</a>
                    {% else %}
                        <a id="show-disqus" class="post-comments-activate" data-disqus-identifier="/{{ article.url }}" >Show Comments</a>
                    {% endif %}
                    <div id="disqus_thread"></div>                  
                </section>
                {% endif %}

                <aside class="post-nav">
                    {% if article.next_article %}
                    <a class="post-nav-next" href="{{ SITEURL }}/{{ article.next_article.url}}">
                        <section class="post-nav-teaser">
                            <i class="ic ic-arrow-left"></i>
                                <h2 class="post-nav-title">{{ article.next_article.title }}</h2>
                            <p class="post-nav-excerpt">{{ article.next_article.summary|striptags|truncate(90) }}</p>
                        </section>
                    </a>
                    {% endif %}
                    {% if article.prev_article %}
                    <a class="post-nav-prev" href="{{ SITEURL }}/{{ article.prev_article.url}}">
                        <section class="post-nav-teaser">
                            <i class="ic ic-arrow-right"></i>
                                <h2 class="post-nav-title">{{ article.prev_article.title }}</h2>
                            <p class="post-nav-excerpt">{{ article.prev_article.summary|striptags|truncate(90) }}</p>
                        </section>
                    </a>
                    {% endif %}
                    <div class="clear"></div>
                </aside>

            </div>
        </article>
    </main>
{% endblock content %}
