From 23434e21029e1b0898770824b472b1caa3fc5dc7 Mon Sep 17 00:00:00 2001 From: Djordje Atlialp Date: Tue, 12 May 2020 09:12:56 +0200 Subject: [PATCH] Add pagination for list views --- README.md | 1 + exampleSite/config.toml | 1 + layouts/_default/list.html | 17 +++++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ca9ac6..593749f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ baseurl = "localhost" title = "My Blog" languageCode = "en-us" theme = "hello-friend-ng" +paginate = 10 [params] dateform = "Jan 2, 2006" diff --git a/exampleSite/config.toml b/exampleSite/config.toml index b98b701..0a15da4 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -8,6 +8,7 @@ theme = "hello-friend-ng" PygmentsCodeFences = true PygmentsStyle = "monokai" +paginate = 10 rssLimit = 10 # Maximum number of items in the RSS feed. copyright = "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License." # This message is only used by the RSS template. diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 24efa70..7e0cb05 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,17 +1,21 @@ {{ define "main" }} + {{ $isntDefault := not (or (eq (trim $.Site.Params.contentTypeName " ") "posts") (eq (trim $.Site.Params.contentTypeName " ") "")) }} + {{ $contentTypeName := cond $isntDefault (string $.Site.Params.contentTypeName) "posts" }} + {{ $paginator := .Paginate (where .Site.RegularPages "Type" $contentTypeName) }} +

{{ .Title }}

- {{- if .Content }} + {{ if .Content }}
{{ .Content }}
- {{- end }} + {{ end }} - {{- range .Data.Pages.GroupByDate "2006" }} + {{ range $paginator.Pages.GroupByDate "2006" }}
{{ .Key }}
- {{- end }} + {{ end }} + {{ partial "pagination.html" . }}
{{ end }}