fix: Pagination reduced links

This commit is contained in:
kbe
2025-08-18 17:17:33 +02:00
parent c5c947c5d7
commit 2135420573

View File

@@ -2,23 +2,65 @@
{{ if gt (len .Site.RegularPages) 10 }}
<nav>
<ul class="pagination justify-content-center mt-5">
<!-- Previous -->
<li class="page-item {{ if not .Paginator.HasPrev }}disabled{{ end }}">
{{ if .Paginator.HasPrev }}
<a class="page-link" href="{{ .Paginator.Prev.URL }}">&laquo;</a>
<a class="page-link" href="{{ .Paginator.Prev.URL }}">&laquo; Previous</a>
{{ else }}
<a class="page-link" href="#">&laquo;</a>
<a class="page-link" href="#">&laquo; Previous</a>
{{ end }}
</li>
<!-- Page numbers -->
{{ $currentPage := .Paginator.PageNumber }}
{{ $totalPages := .Paginator.TotalPages }}
<!-- Always show first page -->
<li class="page-item {{ if eq $currentPage 1 }}active{{ end }}">
<a class="page-link" href="{{ .Paginator.First.URL }}">1</a>
</li>
<!-- Show ellipsis if current page is > 4 -->
{{ if gt $currentPage 4 }}
<li class="page-item disabled">
<span class="page-link">...</span>
</li>
{{ end }}
<!-- Show pages around current page -->
{{ range .Paginator.Pagers }}
<li class="page-item {{ if eq .PageNumber $.Paginator.PageNumber }}active{{ end }}">
<a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a>
{{ $pageNumber := .PageNumber }}
{{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }}
{{ if ne $pageNumber 1 }}
{{ if ne $pageNumber $totalPages }}
<li class="page-item {{ if eq $pageNumber $currentPage }}active{{ end }}">
<a class="page-link" href="{{ .URL }}">{{ $pageNumber }}</a>
</li>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<!-- Show ellipsis if current page is < totalPages - 3 -->
{{ if lt $currentPage (sub $totalPages 3) }}
<li class="page-item disabled">
<span class="page-link">...</span>
</li>
{{ end }}
<!-- Always show last page -->
{{ if gt $totalPages 1 }}
<li class="page-item {{ if eq $currentPage $totalPages }}active{{ end }}">
<a class="page-link" href="{{ .Paginator.Last.URL }}">{{ $totalPages }}</a>
</li>
{{ end }}
<!-- Next -->
<li class="page-item {{ if not .Paginator.HasNext }}disabled{{ end }}">
{{ if .Paginator.HasNext }}
<a class="page-link" href="{{ .Paginator.Next.URL }}">&raquo;</a>
<a class="page-link" href="{{ .Paginator.Next.URL }}">Next &raquo;</a>
{{ else }}
<a class="page-link" href="#">&raquo;</a>
<a class="page-link" href="#">Next &raquo;</a>
{{ end }}
</li>
</ul>