{{ $paginator := .paginator }}
{{ $outer := .outer}}

<!-- Thanks to https://glennmccomb.com/articles/how-to-build-custom-hugo-pagination/ -->

<!-- Show first and last link-->
{{ $show_first_last := $outer.Site.Params.Posts.showFirstLast | default false }}

<!-- Number of links either side of the current page. -->
{{ $adjacent_links := $outer.Site.Params.Posts.paginationPages | default 2 }}

<!-- $max_links = ($adjacent_links * 2) + 1 -->
{{ $max_links := (add (mul $adjacent_links 2) 1) }}

<!-- $lower_limit = $adjacent_links + 1 -->
{{ $lower_limit := (add $adjacent_links 1) }}

<!-- $upper_limit = $paginator.TotalPages - $adjacent_links -->
{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}

{{ if gt $paginator.TotalPages 1 }}
<footer>
    <div class="pagination">
        <ul class="pagination">

            <!-- First page. -->
            {{ if $show_first_last }}
                {{ if ne $paginator.PageNumber 1 }}
                <li>
                    <a href="{{ $paginator.First.URL }}" class="extra first">
                        {{ i18n "PAGINATION_FIRST" . }}
                    </a>
                </li>
                {{ end }}
            {{ end }}
            <!-- Previous page. -->
            {{ if $paginator.HasPrev }}
            <li>
                <a href="{{ $paginator.Prev.URL }}" class="previous">
                    {{ i18n "PAGINATION_PREVIOUS" . }}
                </a>
            </li>
            {{ end }}

            <!-- Информация о страницах для десктопа -->
            <li class="page-info desktop-only">
                <span class="current-page">{{ $paginator.PageNumber }}</span>
                <span class="separator">из</span>
                <span class="total-pages">{{ $paginator.TotalPages }}</span>
            </li>

            <!-- Next page. -->
            {{ if $paginator.HasNext }}
            <li>
                <a href="{{ $paginator.Next.URL }}" class="next">
                    {{ i18n "PAGINATION_NEXT" . }}
                </a>
            </li>
            {{ end }}

            <!-- Last page. -->
            {{ if $show_first_last }}
                {{ if ne $paginator.PageNumber $paginator.TotalPages }}
                <li>
                    <a href="{{ $paginator.Last.URL }}" class="extra last">
                        {{ i18n "PAGINATION_LAST" . }}
                    </a>
                </li>
                {{ end }}
            {{ end }}
        </ul>
    </div>
</footer>
{{ end }}