fix: Pagination reduced links
This commit is contained in:
@@ -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 }}">«</a>
|
||||
<a class="page-link" href="{{ .Paginator.Prev.URL }}">« Previous</a>
|
||||
{{ else }}
|
||||
<a class="page-link" href="#">«</a>
|
||||
<a class="page-link" href="#">« Previous</a>
|
||||
{{ end }}
|
||||
</li>
|
||||
{{ range .Paginator.Pagers }}
|
||||
<li class="page-item {{ if eq .PageNumber $.Paginator.PageNumber }}active{{ end }}">
|
||||
<a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a>
|
||||
|
||||
<!-- 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 }}
|
||||
{{ $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 }}">»</a>
|
||||
<a class="page-link" href="{{ .Paginator.Next.URL }}">Next »</a>
|
||||
{{ else }}
|
||||
<a class="page-link" href="#">»</a>
|
||||
<a class="page-link" href="#">Next »</a>
|
||||
{{ end }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user