{#  -*- coding: utf-8 -*- #}
{% macro page_navigation(current_page, page_links, prevlink, nextlink, prev_next_links_reversed, surrounding=5) %}
<nav aria-label="Page navigation">
  <ul class="pagination">
  {% if prev_next_links_reversed %}
    {% if nextlink %}
      <li class="page-item"><a href="{{ nextlink }}" class="page-link" aria-label="{{ messages("Older posts") }}"><span aria-hidden="true">&laquo;</span></a></li>
    {% else %}
      <li class="page-item disabled"><a href="#" class="page-link" aria-label="{{ messages("Older posts") }}"><span aria-hidden="true">&laquo;</span></a></li>
    {% endif %}
  {% else %}
    {% if prevlink %}
      <li class="page-item"><a href="{{ prevlink }}" class="page-link" aria-label="{{ messages("Newer posts") }}"><span aria-hidden="true">&laquo;</span></a></li>
    {% else %}
      <li class="page-item disabled"><a href="#" class="page-link" aria-label="{{ messages("Newer posts") }}"><span aria-hidden="true">&laquo;</span></a></li>
    {% endif %}
  {% endif %}
  {% for i, link in enumerate(page_links) %}
    {% if (i - current_page)|abs <= surrounding or i == 0 or i == page_links|length - 1 %}
      <li class="page-item {{ 'active' if i == current_page else '' }}"><a href="{{ link }}" class="page-link">{{ i + 1 }}{{ ' <span class="sr-only">(current)</span>' if i == current_page else '' }}</a></li>
    {% elif i == current_page - surrounding - 1 or i == current_page + surrounding + 1 %}
      <li class="page-item disabled"><a href="#" class="page-link" aria-label="…"><span aria-hidden="true">…</span></a></li>
    {% endif %}
  {% endfor %}
  {% if prev_next_links_reversed %}
    {% if prevlink %}
      <li class="page-item"><a href="{{ prevlink }}" class="page-link" aria-label="{{ messages("Newer posts") }}"><span aria-hidden="true">&raquo;</span></a></li>
    {% else %}
      <li class="page-item disabled"><a href="#" class="page-link" aria-label="{{ messages("Newer posts") }}"><span aria-hidden="true">&raquo;</span></a></li>
    {% endif %}
  {% else %}
    {% if nextlink %}
      <li class="page-item"><a href="{{ nextlink }}" class="page-link" aria-label="{{ messages("Older posts") }}"><span aria-hidden="true">&raquo;</span></a></li>
    {% else %}
      <li class="page-item disabled"><a href="#" class="page-link" aria-label="{{ messages("Older posts") }}"><span aria-hidden="true">&raquo;</span></a></li>
    {% endif %}
  {% endif %}
  </ul>
</nav>
{% endmacro %}
