From ffb76332edafa41658298f5211b0817db89764e8 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Tue, 13 Apr 2021 10:19:17 +0200 Subject: [PATCH] added option for infinite scrolling, with fallback regular pagination without javascript --- README.md | 7 ++++ layouts/_default/baseof.json | 1 + layouts/index.html | 3 +- layouts/index.json | 3 ++ layouts/partials/paginator.html | 69 +++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 layouts/_default/baseof.json diff --git a/README.md b/README.md index 1ec028f..3fe3038 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,13 @@ summaryLength = 70 # number of words for article summaries # useful if deploying in gitlab pages with custom domain and don't want # the username.gitlab.io/website url to persist forceRedirect = false + + infiniteScrolling = false # activates infinite scrolling instead of regular pagination + +# this section is necessary if you want infinite scrolling +# it allows to output the article list as paged JSON so that "pages" can be retrieved via javascript +[outputs] + home = ["HTML", "JSON"] ``` ## Inject custom content diff --git a/layouts/_default/baseof.json b/layouts/_default/baseof.json new file mode 100644 index 0000000..49d010f --- /dev/null +++ b/layouts/_default/baseof.json @@ -0,0 +1 @@ +{{- block "main" . }}{{- end }} diff --git a/layouts/index.html b/layouts/index.html index a4bb3a0..eba1899 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -5,7 +5,7 @@ {{ $postsList := where .Site.RegularPages "Section" "in" $postsDir }} {{/* pagination */}} -
+
{{ range (.Paginate $postsList).Pages }}
@@ -37,6 +37,7 @@
{{ end }}
+
{{- partial "paginator.html" . -}} {{ end }} diff --git a/layouts/index.json b/layouts/index.json index 8619099..7d8529c 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -1,3 +1,4 @@ +{{ define "main" }} { {{ $postsDir := .Site.Params.Posts | default (slice "posts" "post") }} {{ $postsList := where .Site.RegularPages "Section" "in" $postsDir }} @@ -8,6 +9,7 @@ "articles": [ {{ range $i, $e := (.Paginate $postsList).Pages }} {{ if $i }}, {{ end }}{ + "ignore": {{ not (in $postsDir .Section) | jsonify }}, "title": {{ .Title | jsonify }}, "date": {{ .Date.Format "2006-01-02" | jsonify }}, "tags": {{ if .Params.tags }} @@ -26,3 +28,4 @@ {{ end }} ] } +{{ end }} diff --git a/layouts/partials/paginator.html b/layouts/partials/paginator.html index ec90e0d..ad25991 100644 --- a/layouts/partials/paginator.html +++ b/layouts/partials/paginator.html @@ -1,3 +1,71 @@ +{{ if .Site.Params.infiniteScrolling }} + +{{ end }} +{{ if .Site.Params.infiniteScrolling }}