Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zwbetz-gh/papercss-hugo-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Miller <me@r15cookie.com>2021-06-08 03:16:17 +0300
committerGitHub <noreply@github.com>2021-06-08 03:16:17 +0300
commit83b6770fa0eef20b860a6c77e4b42d240c95755a (patch)
tree05e134e4d9c548aafd6b0f38ad3610a6ac019375
parent76d050f5a0c79d33622b5a4c79e9fa13d818ce5a (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.yaml3
-rw-r--r--layouts/index.html6
-rw-r--r--layouts/partials/pagination.html45
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">&laquo;&laquo;</a>
+ {{ end -}}
+ <a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}"{{ end }} class="paper-btn{{ if not $pag.HasPrev }} disabled{{ end }}">&laquo;</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>&nbsp;&hellip;&nbsp;</button>
+
+ {{- end -}}
+ {{- end }}
+
+ <a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}"{{ end }} class="paper-btn {{ if not $pag.HasNext }} disabled{{ end }}">&raquo;</a>
+
+ {{- with $pag.Last }}
+
+ <a href="{{ .URL }}" class="paper-btn">&raquo;&raquo;</a>
+
+ {{- end }}
+ </div>
+
+
+{{ end }} \ No newline at end of file