{% if not PAGINATOR_LIMIT %}
    {% set PAGINATOR_LIMIT = 8 %}
{% endif -%}

{%- if articles_page and articles_paginator.num_pages > 1 %}
    <div class="text-center">
        <ul class="pagination">
            {% if articles_page.has_previous() %}
                {% set num = articles_page.previous_page_number() %}
                <li class="prev">
                    <a href="{{ SITEURL }}/{{ articles_previous_page.url }}">
                        <i class="fa fa-arrow-circle-left"></i>
                    </a>
                </li>
            {% else %}
                <li class="prev disabled"><a href="#">
                    <i class="fa fa-arrow-circle-left"></i>
                </a></li>
            {% endif -%}

            {%- for num in range( 1, 1 + articles_paginator.num_pages ) %}
                {% set print_number = False %}
                {% set dots_before = True %}
                {% if num == 1 %}
                    {% set print_number = True %}
                    {% set dots_before = False %}
                {% elif (articles_page.number - PAGINATOR_LIMIT/2) <= num < (articles_page.number - PAGINATOR_LIMIT/2 + 1) %}
                    {% set print_number = True %}
                    {% if num == 2 %}
                        {% set dots_before = False %}
                    {% endif %}
                {% elif (articles_page.number - PAGINATOR_LIMIT/2 + 1) <= num <= (articles_page.number + PAGINATOR_LIMIT/2) %}
                    {% set print_number = True %}
                    {% set dots_before = False %}
                {% elif num == articles_paginator.num_pages %}
                    {% set print_number = True %}
                    {% if (articles_page.number + PAGINATOR_LIMIT/2) <= num <= (articles_page.number + PAGINATOR_LIMIT/2 + 1) %}
                        {% set dots_before = False %}
                    {% endif %}
                {% endif -%}

                {%- if print_number %}
                    {%- if dots_before %}
                        <li class="disabled"><a href="#">...</a></li>
                    {% endif %}
                    <li class="{{ 'active' if num == articles_page.number else '' }}"><a
                        href="{{ SITEURL }}/{{ page_name }}{{ num if num > 1 else '' }}.html">{{ num }}</a></li>
                {% endif -%}
            {% endfor -%}

            {%- if articles_page.has_next() %}
                <li class="next">
                    <a href="{{ SITEURL }}/{{ articles_next_page.url }}">
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </li>
            {% else %}
                <li class="next disabled"><a href="#">
                    <i class="fa fa-arrow-circle-right"></i>
                </a></li>
            {%- endif %}
        </ul>
        <p><a href="{{ SITEURL -}} / {{- ARCHIVES_URL }}">Click to see every post in a big list</a></p>
    </div>
{% endif -%}