diff options
author | Steve Miller <me@r15cookie.com> | 2021-06-08 03:16:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 03:16:17 +0300 |
commit | 83b6770fa0eef20b860a6c77e4b42d240c95755a (patch) | |
tree | 05e134e4d9c548aafd6b0f38ad3610a6ac019375 | |
parent | 76d050f5a0c79d33622b5a4c79e9fa13d818ce5a (diff) |
Pagination Support (#11)
* Absolute links to Relative Links
* Additional updates to permalinks
Signed-off-by: Steve Miller <me@r15cookie.com>
* Pagination support
Signed-off-by: Steve Miller <me@r15cookie.com>
* Updates to disabling pagination comment
* Update disablement comment
Signed-off-by: Steve Miller <me@r15cookie.com>
-rw-r--r-- | exampleSite/config.yaml | 3 | ||||
-rw-r--r-- | layouts/index.html | 6 | ||||
-rw-r--r-- | layouts/partials/pagination.html | 45 |
3 files changed, 52 insertions, 2 deletions
diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index dfd7283..5637b83 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -19,6 +19,9 @@ permalinks: imaging: quality: 99 +# To disable, set to an extremely large value, such as 999999 +paginate: 5 + params: homeMetaContent: A Hugo theme made with PaperCSS, the less formal CSS framework. # For more date formats see https://gohugo.io/functions/format/ diff --git a/layouts/index.html b/layouts/index.html index 283c619..544d78c 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -2,8 +2,9 @@ <h1>{{ .Title }}</h1> {{ .Content }} -{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} -{{ range $pages.ByPublishDate.Reverse }} +{{ $paginator := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections) }} + +{{ range $paginator.Pages.ByPublishDate.Reverse }} <h2 class="post-list {{ if ne .Params.show_summary false }}summary{{ end }}"> <a href="{{ .RelPermalink }}"> {{ .Title }} @@ -13,4 +14,5 @@ {{ .Summary }} {{ end }} {{ end }} +{{ template "partials/pagination.html" . }} {{ end }} diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 0000000..90a278c --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,45 @@ +{{ $pag := $.Paginator }} +{{ if gt $pag.TotalPages 1 -}} + + <div class="row flex-center margin-top-large"> + + {{ with $pag.First -}} + <a href="{{ .URL }}" class="paper-btn">««</a> + {{ end -}} + <a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }} class="paper-btn{{ if not $pag.HasPrev }} disabled{{ end }}">«</a> + {{- $ellipsed := false -}} + {{- $shouldEllipse := false -}} + {{- range $pag.Pagers -}} + {{- $right := sub .TotalPages .PageNumber -}} + {{- $showNumber := or (le .PageNumber 3) (eq $right 0) -}} + {{- $showNumber := or $showNumber (le .TotalPages 5) -}}{{/* Issue #7523 */}} + {{- $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) -}} + {{- if $showNumber -}} + {{- $ellipsed = false -}} + {{- $shouldEllipse = false -}} + {{- else -}} + {{- $shouldEllipse = not $ellipsed -}} + {{- $ellipsed = true -}} + {{- end -}} + {{- if $showNumber }} + + <a class="paper-btn{{ if eq . $pag }} active{{ end }}" href="{{ .URL }}">{{ .PageNumber }}</a> + + {{- else if $shouldEllipse }} + + <button> … </button> + + {{- end -}} + {{- end }} + + <a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }} class="paper-btn {{ if not $pag.HasNext }} disabled{{ end }}">»</a> + + {{- with $pag.Last }} + + <a href="{{ .URL }}" class="paper-btn">»»</a> + + {{- end }} + </div> + + +{{ end }}
\ No newline at end of file |