diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-11-16 19:32:18 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-11-17 01:28:57 +0300 |
commit | 239d68f94c6250276850fbe95eaa6cdd5c38fb26 (patch) | |
tree | c576da169afc442f51eae6213ad0ff749ed86589 /themes/neonxp/layouts/partials/pagination.html | |
parent | 8e79098193fd0a8b65305dd8054cf7c424c60bc5 (diff) |
Своя тема, полностью всё переделал
Diffstat (limited to 'themes/neonxp/layouts/partials/pagination.html')
-rw-r--r-- | themes/neonxp/layouts/partials/pagination.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/themes/neonxp/layouts/partials/pagination.html b/themes/neonxp/layouts/partials/pagination.html new file mode 100644 index 0000000..ee7a171 --- /dev/null +++ b/themes/neonxp/layouts/partials/pagination.html @@ -0,0 +1,98 @@ +{{- $validFormats := slice "default" "terse" }} + +{{- $msg1 := "When passing a map to the internal pagination template, one of the elements must be named 'page', and it must be set to the context of the current page." }} +{{- $msg2 := "The 'format' specified in the map passed to the internal pagination template is invalid. Valid choices are: %s." }} + +{{- $page := . }} +{{- $format := "default" }} + +{{- if reflect.IsMap . }} + {{- with .page }} + {{- $page = . }} + {{- else }} + {{- errorf $msg1 }} + {{- end }} + {{- with .format }} + {{- $format = lower . }} + {{- end }} +{{- end }} + +{{- if in $validFormats $format }} + {{- if gt $page.Paginator.TotalPages 1 }} + <ul class="pagination pagination-{{ $format }}"> + {{- partial (printf "partials/inline/pagination/%s" $format) $page }} + </ul> + {{- end }} +{{- else }} + {{- errorf $msg2 (delimit $validFormats ", ") }} +{{- end -}} + +{{/* --------------------------------------------------------------------- */}} +{{- define "partials/inline/pagination/default" }} + {{- with .Paginator }} + {{- $currentPageNumber := .PageNumber }} + + {{- with .First }} + {{- if ne $currentPageNumber .PageNumber }} + <li class="page-item"> + <a href="{{ .URL }}" aria-label="First" class="page-link"><span aria-hidden="true">⇚</span></a> + </li> + {{- else }} + <li class="page-item disabled"> + <a aria-disabled="true" aria-label="First" class="page-link" tabindex="-1"><span aria-hidden="true">⇚</span></a> + </li> + {{- end }} + {{- end }} + + {{- with .Prev }} + <li class="page-item"> + <a href="{{ .URL }}" aria-label="Previous" class="page-link"><span aria-hidden="true">←</span></a> + </li> + {{- else }} + <li class="page-item disabled"> + <a aria-disabled="true" aria-label="Previous" class="page-link" tabindex="-1"><span aria-hidden="true">←</span></a> + </li> + {{- end }} + + {{- $slots := 5 }} + {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }} + {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }} + {{- if lt (add (sub $end $start) 1) $slots }} + {{- $start = math.Max 1 (add (sub $end $slots) 1) }} + {{- end }} + + {{- range $k := seq $start $end }} + {{- if eq $.Paginator.PageNumber $k }} + <li class="page-item active"> + [{{ $k }}] + </li> + {{- else }} + <li class="page-item"> + <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link">{{ $k }}</a> + </li> + {{- end }} + {{- end }} + + {{- with .Next }} + <li class="page-item"> + <a href="{{ .URL }}" aria-label="Next" class="page-link"><span aria-hidden="true">→</span></a> + </li> + {{- else }} + <li class="page-item disabled"> + <a aria-disabled="true" aria-label="Next" class="page-link" tabindex="-1"><span aria-hidden="true">→</span></a> + </li> + {{- end }} + + {{- with .Last }} + {{- if ne $currentPageNumber .PageNumber }} + <li class="page-item"> + <a href="{{ .URL }}" aria-label="Last" class="page-link"><span aria-hidden="true">⇛</span></a> + </li> + {{- else }} + <li class="page-item disabled"> + <a aria-disabled="true" aria-label="Last" class="page-link" tabindex="-1"><span aria-hidden="true">⇛</span></a> + </li> + {{- end }} + {{- end }} + {{- end }} +{{- end -}}
\ No newline at end of file |