{% extends "base.html" %}

{% block title %}{{ SITENAME }} | {{ category }} {% endblock %}

{% block content %}

{% if articles_page and articles_paginator.num_pages > 1 %}

    <!-- Previous / next buttons -->
    <div class='paginator'>
    {% if articles_page.has_previous() %}
            <a href="{{SITE_URL}}/category/{{ category.slug }}
            {% if articles_page.number > 2%}{{ articles_page.number - 1}}{% endif %}.html">«
            </a>
    {% endif %}
    <span class="page_numbers">{{ articles_page.number }} / {{ articles_paginator.num_pages }}</span>

    {% if articles_page.has_next() %}
        <a href="{{SITE_URL}}/category/{{ category.slug }}{{ articles_page.number + 1}}.html">»</a>
    {% endif %}
        </div>

    {% for i in range (0, DEFAULT_PAGINATION ) %}
        {% set index = (articles_page.number - 1) * DEFAULT_PAGINATION %}
        {% if index + i < articles|length %}
            {% set article = articles[index + i] %}
            <h2><a href="{{ SITE_URL }}/{{ article.url }}">{{article.title}}</a></h2>
            <bold>{{ article.date |strftime('%d.%m.%Y') }}</bold>
            <p>---</p>
        {% endif %}
    {% endfor %}

    {% for article in articles %}

    {% endfor %}

<!-- If pagination is not necessary -->
{% else %}
{% for article in articles %}
    <h2><a href="{{ SITE_URL }}/{{ article.url }}">{{article.title}}</a></h2>
    <bold>{{ article.date |strftime('%d.%m.%Y') }}</bold>
    <p>---</p>
{% endfor %}
{% endif %}

{% endblock content %}
