aboutsummaryrefslogtreecommitdiffstats
path: root/layouts/partials/pagination.html
diff options
context:
space:
mode:
authorLuiz F. A. de Prá <rawarkanis@gmail.com>2018-02-28 22:38:59 -0300
committerLuiz F. A. de Prá <rawarkanis@gmail.com>2018-02-28 22:38:59 -0300
commit4db982bb015eddb624e4c7f5776596b166dbaae5 (patch)
tree7c54044af415f43f3f2ecb2dc44ec01628e31893 /layouts/partials/pagination.html
downloadhugo-coder-4db982bb015eddb624e4c7f5776596b166dbaae5.tar.gz
hugo-coder-4db982bb015eddb624e4c7f5776596b166dbaae5.tar.bz2
hugo-coder-4db982bb015eddb624e4c7f5776596b166dbaae5.zip
Initial files
Diffstat (limited to 'layouts/partials/pagination.html')
-rw-r--r--layouts/partials/pagination.html48
1 files changed, 48 insertions, 0 deletions
diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html
new file mode 100644
index 0000000..1e004b8
--- /dev/null
+++ b/layouts/partials/pagination.html
@@ -0,0 +1,48 @@
+{{ $paginator := .Paginator }}
+{{ $adjacent_links := 2 }}
+{{ $max_links := (add (mul $adjacent_links 2) 1) }}
+{{ $lower_limit := (add $adjacent_links 1) }}
+{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
+{{ if gt $paginator.TotalPages 1 }}
+<ul class="pagination">
+ {{ if $paginator.HasPrev }}
+ {{ if ne $paginator.PageNumber 1 }}
+ <li><a href="{{ $paginator.First.URL }}">&laquo;</a></li>
+ {{ end }}
+ <li class="hidden"><a href="{{ $paginator.Prev.URL }}">&lsaquo;</a></li>
+ {{ end }}
+ {{ range $paginator.Pagers }}
+ {{ $.Scratch.Set "page_number_flag" false }}
+ {{ if gt $paginator.TotalPages $max_links }}
+ {{ if le $paginator.PageNumber $lower_limit }}
+ {{ if le .PageNumber $max_links }}
+ {{ $.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+ {{ else if ge $paginator.PageNumber $upper_limit }}
+ {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
+ {{ $.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+ {{ else }}
+ {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
+ {{ $.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+ {{ end }}
+ {{ else }}
+ {{ $.Scratch.Set "page_number_flag" true }}
+ {{ end }}
+ {{ if eq ($.Scratch.Get "page_number_flag") true }}
+ {{ if eq . $paginator }}
+ <li>{{ .PageNumber }}</li>
+ {{ else }}
+ <li><a href="{{ .URL }}">{{ .PageNumber }}</a></li>
+ {{ end }}
+ {{ end }}
+ {{ end }}
+ {{ if $paginator.HasNext }}
+ <li class="hidden"><a href="{{ $paginator.Next.URL }}">&rsaquo;</a></li>
+ {{ if ne $paginator.PageNumber $paginator.TotalPages }}
+ <li><a href="{{ $paginator.Last.URL }}">&raquo;</a></li>
+ {{ end }}
+ {{ end }}
+</ul>
+{{ end }}