diff options
author | DSRKafuU | 2021-03-01 09:19:56 +0800 |
---|---|---|
committer | GitHub | 2021-03-01 09:19:56 +0800 |
commit | edc2968451aeabb3ee5bb4a90730a6980318aca8 (patch) | |
tree | ed5f490b435caeadcd5d0e4affc5b52407373c46 /layouts/partials/pagination.html | |
parent | ef5bd83b41e7816ba9822fb507860d54e4760cc8 (diff) | |
parent | 5d8e60e724fef437d65a6f86780d4f771b154ef6 (diff) | |
download | hugo-theme-fuji-edc2968451aeabb3ee5bb4a90730a6980318aca8.tar.gz hugo-theme-fuji-edc2968451aeabb3ee5bb4a90730a6980318aca8.tar.bz2 hugo-theme-fuji-edc2968451aeabb3ee5bb4a90730a6980318aca8.zip |
fix(pagi): pull request #68 from Qraffa/master
update: tag pagination
Diffstat (limited to 'layouts/partials/pagination.html')
-rw-r--r-- | layouts/partials/pagination.html | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 0000000..3db973f --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,56 @@ +{{- $paginator := .pagi -}} +{{- $scratch := newScratch -}} +<!-- custom smart pagination --> +{{- $offsetLinks := 2 -}} +{{- $maxLinks := (add (mul $offsetLinks 2) 1) -}} +{{- $lowerLimit := (add $offsetLinks 1) -}} +{{- $upperLimit := (sub $paginator.TotalPages $offsetLinks) -}} +{{- if gt $paginator.TotalPages 1 -}} +<div class="pagination"> + {{- if ne $paginator.PageNumber 1 -}} + <div class="pag-first"> + <a href="{{ $paginator.First.URL }}"><i class="iconfont icon-caret-back-circle-sharp"></i></a> + </div> + {{- end -}} + {{- if $paginator.HasPrev -}} + <div class="pag-previous"> + <a href="{{ $paginator.Prev.URL }}"><i class="iconfont icon-chevron-back-circle-sharp"></i></a> + </div> + {{- end -}} + {{- range $paginator.Pagers -}} + {{- $scratch.Set "pageNumFlag" false -}} + {{- if gt $paginator.TotalPages $maxLinks -}} + {{- if le $paginator.PageNumber $lowerLimit -}} + {{- if le .PageNumber $maxLinks -}} + {{- $scratch.Set "pageNumFlag" true -}} + {{- end -}} + {{- else if ge $paginator.PageNumber $upperLimit -}} + {{- if gt .PageNumber (sub $paginator.TotalPages $maxLinks) -}} + {{- $scratch.Set "pageNumFlag" true -}} + {{- end -}} + {{- else -}} + {{- if and ( ge .PageNumber (sub $paginator.PageNumber $offsetLinks) ) ( le .PageNumber (add $paginator.PageNumber $offsetLinks) ) -}} + {{- $scratch.Set "pageNumFlag" true -}} + {{- end -}} + {{- end -}} + {{- else -}} + {{- $scratch.Set "pageNumFlag" true -}} + {{- end -}} + {{- if eq ($scratch.Get "pageNumFlag") true -}} + <div class="pag-item{{ if eq . $paginator }} pag-current{{ end }}"> + <a href="{{ .URL }}">{{- .PageNumber -}}</a> + </div> + {{- end -}} + {{- end -}} + {{- if $paginator.HasNext -}} + <div class="pag-next"> + <a href="{{ $paginator.Next.URL }}"><i class="iconfont icon-chevron-forward-circle-sharp"></i></a> + </div> + {{- end -}} + {{- if ne $paginator.PageNumber $paginator.TotalPages -}} + <div class="pag-last"> + <a href="{{ $paginator.Last.URL }}"><i class="iconfont icon-caret-forward-circle-sharp"></i></a> + </div> + {{- end -}} +</div> +{{- end -}} |