|
| 1 | +{{ $paginator := .Paginator }} |
| 2 | +<!-- Number of links either side of the current page. --> |
| 3 | +{{ $adjacent_links := 2 }} |
| 4 | +<!-- $max_links = ($adjacent_links * 2) + 1 --> |
| 5 | +{{ $max_links := (add (mul $adjacent_links 2) 1) }} |
| 6 | +<!-- $lower_limit = $adjacent_links + 1 --> |
| 7 | +{{ $lower_limit := (add $adjacent_links 1) }} |
| 8 | +<!-- $upper_limit = $paginator.TotalPages - $adjacent_links --> |
| 9 | +{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }} |
| 10 | +<!-- If there's more than one page. --> |
| 11 | +{{ if gt $paginator.TotalPages 1 }} |
| 12 | + <nav |
| 13 | + class="flex items-center justify-center space-x-3" |
| 14 | + aria-label="Pagination"> |
| 15 | + <!-- Previous page. --> |
| 16 | + {{ if $paginator.HasPrev }} |
| 17 | + <a |
| 18 | + class="text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light rounded px-2 py-1.5" |
| 19 | + href="{{ $paginator.Prev.URL }}" |
| 20 | + aria-label="Pagination Arrow"> |
| 21 | + <span class="sr-only">Previous</span> |
| 22 | + <svg |
| 23 | + viewBox="0 0 20 20" |
| 24 | + fill="currentColor" |
| 25 | + aria-hidden="true" |
| 26 | + height="30" |
| 27 | + width="30"> |
| 28 | + <path |
| 29 | + fill-rule="evenodd" |
| 30 | + d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" |
| 31 | + clip-rule="evenodd" /> |
| 32 | + </svg> |
| 33 | + </a> |
| 34 | + {{ else }} |
| 35 | + <span class="text-light rounded px-2 py-1.5"> |
| 36 | + <span class="sr-only">Previous</span> |
| 37 | + <svg |
| 38 | + viewBox="0 0 20 20" |
| 39 | + fill="currentColor" |
| 40 | + aria-hidden="true" |
| 41 | + height="30" |
| 42 | + width="30"> |
| 43 | + <path |
| 44 | + fill-rule="evenodd" |
| 45 | + d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" |
| 46 | + clip-rule="evenodd" /> |
| 47 | + </svg> |
| 48 | + </span> |
| 49 | + {{ end }} |
| 50 | + |
| 51 | + |
| 52 | + <!-- Page numbers --> |
| 53 | + {{ range $paginator.Pagers }} |
| 54 | + {{ $.Scratch.Set "page_number_flag" false }} |
| 55 | + <!-- Advanced page numbers. --> |
| 56 | + {{ if gt $paginator.TotalPages $max_links }} |
| 57 | + <!-- Lower limit pages. --> |
| 58 | + <!-- If the user is on a page which is in the lower limit. --> |
| 59 | + {{ if le $paginator.PageNumber $lower_limit }} |
| 60 | + <!-- If the current loop page is less than max_links. --> |
| 61 | + {{ if le .PageNumber $max_links }} |
| 62 | + {{ $.Scratch.Set "page_number_flag" true }} |
| 63 | + {{ end }} |
| 64 | + <!-- Upper limit pages. --> |
| 65 | + <!-- If the user is on a page which is in the upper limit. --> |
| 66 | + {{ else if ge $paginator.PageNumber $upper_limit }} |
| 67 | + <!-- If the current loop page is greater than total pages minus $max_links --> |
| 68 | + {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }} |
| 69 | + {{ $.Scratch.Set "page_number_flag" true }} |
| 70 | + {{ end }} |
| 71 | + <!-- Middle pages. --> |
| 72 | + {{ else }} |
| 73 | + {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }} |
| 74 | + {{ $.Scratch.Set "page_number_flag" true }} |
| 75 | + {{ end }} |
| 76 | + {{ end }} |
| 77 | + <!-- Simple page numbers. --> |
| 78 | + {{ else }} |
| 79 | + {{ $.Scratch.Set "page_number_flag" true }} |
| 80 | + {{ end }} |
| 81 | + <!-- Output page numbers. --> |
| 82 | + {{ if eq ($.Scratch.Get "page_number_flag") true }} |
| 83 | + |
| 84 | + {{ if eq . $paginator }} |
| 85 | + <span |
| 86 | + aria-current="page" |
| 87 | + class="bg-primary dark:bg-darkmode-primary dark:text-dark rounded px-4 py-2 text-white"> |
| 88 | + {{ .PageNumber }} |
| 89 | + </span> |
| 90 | + {{ else }} |
| 91 | + <a |
| 92 | + href="{{ .URL }}" |
| 93 | + aria-current="page" |
| 94 | + class="text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light rounded px-4 py-2"> |
| 95 | + {{ .PageNumber }} |
| 96 | + </a> |
| 97 | + {{ end }} |
| 98 | + {{ end }} |
| 99 | + {{ end }} |
| 100 | + |
| 101 | + |
| 102 | + <!-- Next page. --> |
| 103 | + {{ if $paginator.HasNext }} |
| 104 | + <a |
| 105 | + class="text-dark hover:bg-theme-light dark:text-darkmode-dark dark:hover:bg-darkmode-theme-light rounded px-2 py-1.5" |
| 106 | + href="{{ $paginator.Next.URL }}" |
| 107 | + aria-label="Pagination Arrow"> |
| 108 | + <span class="sr-only">Next</span> |
| 109 | + <svg |
| 110 | + viewBox="0 0 20 20" |
| 111 | + fill="currentColor" |
| 112 | + aria-hidden="true" |
| 113 | + height="30" |
| 114 | + width="30"> |
| 115 | + <path |
| 116 | + fill-rule="evenodd" |
| 117 | + d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" |
| 118 | + clip-rule="evenodd" /> |
| 119 | + </svg> |
| 120 | + </a> |
| 121 | + {{ else }} |
| 122 | + <span class="text-light rounded px-2 py-1.5"> |
| 123 | + <span class="sr-only">Next</span> |
| 124 | + <svg |
| 125 | + viewBox="0 0 20 20" |
| 126 | + fill="currentColor" |
| 127 | + aria-hidden="true" |
| 128 | + height="30" |
| 129 | + width="30"> |
| 130 | + <path |
| 131 | + fill-rule="evenodd" |
| 132 | + d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" |
| 133 | + clip-rule="evenodd" /> |
| 134 | + </svg> |
| 135 | + </span> |
| 136 | + {{ end }} |
| 137 | + </nav> |
| 138 | +{{ end }} |
0 commit comments