|
| 1 | +{{/* |
| 2 | + Pagination — condenses long page lists to: first 2, last 2, current ±1, |
| 3 | + with ellipsis fillers. Renders nothing when there's only one page. |
| 4 | + |
| 5 | + Params (passed as a dict): |
| 6 | + paginator (required) — a Hugo Paginator (e.g. .Paginator or a custom .Paginate result) |
| 7 | + id (optional) — id attribute for the <nav> wrapper |
| 8 | + class (optional) — class for the <nav>, defaults to "mt-16" |
| 9 | +*/}} |
| 10 | +{{ $paginator := .paginator }} |
| 11 | +{{ $id := .id }} |
| 12 | +{{ $class := .class | default "mt-16" }} |
| 13 | + |
| 14 | +{{ if gt $paginator.TotalPages 1 }} |
| 15 | + <nav{{ with $id }} id="{{ . }}"{{ end }} aria-label="Page navigation" class="{{ $class }}"> |
| 16 | + <ul class="pagination justify-center"> |
| 17 | + {{ if $paginator.HasPrev }} |
| 18 | + <li class="page-item"> |
| 19 | + <a class="page-link" href="{{ $paginator.Prev.URL }}" aria-label="Previous"> |
| 20 | + <i class="fas fa-chevron-left"></i> |
| 21 | + </a> |
| 22 | + </li> |
| 23 | + {{ end }} |
| 24 | + |
| 25 | + {{ $currentPage := $paginator.PageNumber }} |
| 26 | + {{ $totalPages := $paginator.TotalPages }} |
| 27 | + |
| 28 | + {{ range $paginator.Pagers }} |
| 29 | + {{ $pageNum := .PageNumber }} |
| 30 | + {{ if or (le $pageNum 2) (ge $pageNum (sub $totalPages 1)) (and (ge $pageNum (sub $currentPage 1)) (le $pageNum (add $currentPage 1))) }} |
| 31 | + <li class="page-item {{ if eq . $paginator }}active{{ end }}"> |
| 32 | + <a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a> |
| 33 | + </li> |
| 34 | + {{ else if or (eq $pageNum 3) (eq $pageNum (sub $totalPages 2)) }} |
| 35 | + <li class="page-item disabled"> |
| 36 | + <span class="page-link">…</span> |
| 37 | + </li> |
| 38 | + {{ end }} |
| 39 | + {{ end }} |
| 40 | + |
| 41 | + {{ if $paginator.HasNext }} |
| 42 | + <li class="page-item"> |
| 43 | + <a class="page-link" href="{{ $paginator.Next.URL }}" aria-label="Next"> |
| 44 | + <i class="fas fa-chevron-right"></i> |
| 45 | + </a> |
| 46 | + </li> |
| 47 | + {{ end }} |
| 48 | + </ul> |
| 49 | + </nav> |
| 50 | +{{ end }} |
0 commit comments