{% extends "layout.html" %}

{% block body %}
<body id="post-index"{% if show_header %} class="feature"{% endif %}>

    {% if show_header %}
    <div class="entry-header">
        <div class="entry-image">
            <img src="{{ url_for('static', filename=config["SITE_HEADER"]) }}">
        </div>

        <div class="image-credit">
            Image source: {{ config.SITE_HEADER_COPYRIGHT }}
        </div>
    </div>
    {% include "includes/nav.html" %}
    {% endif %}

    <header class="header-title">
        <div class="header-title-wrap">
        {% block header_title scoped %}
            <h1 class="entry-title"><a href="">{{ title }}</a></h1>
        {% endblock %}
        </div>
    </header>

    {% block inner_body %}{% endblock %}

    <div id="main" role="main">
        {% block main %}
        <div id="items">
            {% for post in posts %}
            <article class="hentry" data-published="{{ not post.draft }}">
                <header>
                    <div class="entry-meta">
                        {% block entry_meta scoped %}
                            <span class="entry-date date published updated">
                                <time datetime="{{ post.posted.isoformat() }}"><a href="">{{ post.posted.date() }}</a></time>
                            </span>
                            <span class="pull-right">
                                <i class="fa fa-comments"></i>
                                <a href="{{ url_for('view_post', slug=post.slug) }}" data-disqus-identifier="{{ post.id }}">
                                    Comments
                                </a>
                            </span>
                        {% endblock %}
                    </div><!-- /.entry-meta -->

                    <h1 class="entry-title">
                        {% block entry_title scoped %}
                            <a href="{{ url_for('view_post', slug=post.slug) }}" rel="bookmark" title="{{ post.title }}">
                                {{ post.title }}
                            </a>
                        {% endblock %}
                    </h1>
                </header>
                {% if not post.draft %}
                <div class="entry-content">
                    {% block entry_content scoped %}
                        {{ post.rendered_content()|safe }}
                    {% endblock %}
                </div><!-- /.entry-content -->
                {% endif %}
            </article><!-- /.hentry -->
            {% endfor %}
        </div>
        {% endblock %}

        {% if paginator %}
            <div class="pagination">
                {% if paginator.has_prev %}
                    <a href="{{ request.path }}?page={{ paginator.previous }}" class="btn">Previous</a>
                {% endif %}
                <ul class="inline-list">
                    {% for idx in paginator.iter_pages() %}
                    <li>
                        {% if idx == paginator.page %}
                            <span class="current-page">{{ paginator.page }}</span>
                        {% else %}
                            <a href="{{ request.path }}?page={{ idx }}">{{ idx }}</a>
                        {% endif %}
                    </li>
                    {% endfor %}
                </ul>
                {% if paginator.has_next %}
                    <a href="{{ request.path }}?page={{ paginator.next }}" class="btn">Next </a>
                {% endif %}
            </div>
        {% endif %}

        {% block main_bottom %}{% endblock %}
    </div>
</body>

{% endblock %}

{% block extra_scripts %}
    {% if config.DISQUS_SHORTNAME %}
    <script type="text/javascript">
        var disqus_shortname = '{{ config.DISQUS_SHORTNAME }}';

        (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = '//' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
        }());
    </script>
    {% endif %}
    {{ super() }}
{% endblock %}