fix: pagination in list.html

This commit is contained in:
kbe
2025-08-18 18:16:18 +02:00
parent 0089c93afa
commit 67d08d9865
3 changed files with 93 additions and 32 deletions

View File

@@ -1,23 +1,25 @@
<!-- Pagination -->
{{ if gt (len .Site.RegularPages) 10 }}
{{ $paginator := .Paginator }}
{{ $page := .Page }}
{{ if gt $paginator.TotalPages 1 }}
<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; Previous</a>
<li class="page-item {{ if not $paginator.HasPrev }}disabled{{ end }}">
{{ if $paginator.HasPrev }}
<a class="page-link" href="{{ $paginator.Prev.URL }}">&laquo; Précédent</a>
{{ else }}
<a class="page-link" href="#">&laquo; Previous</a>
<a class="page-link" href="#">&laquo; Précédent</a>
{{ end }}
</li>
<!-- Page numbers -->
{{ $currentPage := .Paginator.PageNumber }}
{{ $totalPages := .Paginator.TotalPages }}
{{ $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>
<a class="page-link" href="{{ $paginator.First.URL }}">1</a>
</li>
<!-- Show ellipsis if current page is > 4 -->
@@ -28,7 +30,7 @@
{{ end }}
<!-- Show pages around current page -->
{{ range .Paginator.Pagers }}
{{ range $paginator.Pagers }}
{{ $pageNumber := .PageNumber }}
{{ if and (gt $pageNumber 1) (lt $pageNumber $totalPages) (ge $pageNumber (sub $currentPage 1)) (le $pageNumber (add $currentPage 1)) }}
{{ if ne $pageNumber 1 }}
@@ -51,16 +53,16 @@
<!-- 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>
<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 }}">Next &raquo;</a>
<li class="page-item {{ if not $paginator.HasNext }}disabled{{ end }}">
{{ if $paginator.HasNext }}
<a class="page-link" href="{{ $paginator.Next.URL }}">Suivant &raquo;</a>
{{ else }}
<a class="page-link" href="#">Next &raquo;</a>
<a class="page-link" href="#">Suivant &raquo;</a>
{{ end }}
</li>
</ul>