diff --git a/config/_default/params.toml b/config/_default/params.toml index b7408a5..1dbddfd 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -2,6 +2,11 @@ mainSections = ["post"] featuredImageField = "image" rssFullContent = true +# Accepted values: "default", "lastmod" +# default = see https://gohugo.io/quick-reference/glossary/#default-sort-order +# lastmod = sort by last modified date, in descending order +SortBy = "default" + [footer] since = 2026 customText = "" diff --git a/layouts/_partials/helper/pages-sort.html b/layouts/_partials/helper/pages-sort.html new file mode 100644 index 0000000..9f767c6 --- /dev/null +++ b/layouts/_partials/helper/pages-sort.html @@ -0,0 +1,7 @@ +{{- $pages := .Pages -}} + +{{- if eq .Context.Site.Params.SortBy "lastmod" -}} + {{- $pages = $pages.ByLastmod.Reverse -}} +{{- end -}} + +{{- return $pages -}} \ No newline at end of file diff --git a/layouts/_partials/helper/pages.html b/layouts/_partials/helper/pages.html new file mode 100644 index 0000000..bca070a --- /dev/null +++ b/layouts/_partials/helper/pages.html @@ -0,0 +1,16 @@ +{{- $pages := .Pages -}} + +{{- if .IsHome -}} + {{- $pages = where .Site.RegularPages "Type" "in" .Site.Params.mainSections -}} +{{- else if or (eq .Kind "section") (eq .Kind "taxonomy") (eq .Kind "term") -}} + {{- $subsections := .Sections -}} + {{- $pages = .Pages | complement $subsections -}} + + {{- if eq (len $pages) 0 -}} + {{- $pages = $subsections -}} + {{- end -}} +{{- end -}} + +{{- $pages := partial "helper/pages-sort.html" (dict "Pages" $pages "Context" .) -}} + +{{- return $pages -}} diff --git a/layouts/_partials/helper/paginator.html b/layouts/_partials/helper/paginator.html index 2153abf..bba32a3 100644 --- a/layouts/_partials/helper/paginator.html +++ b/layouts/_partials/helper/paginator.html @@ -1,26 +1,8 @@ -{{- $pages := slice -}} -{{- $hasPages := false -}} +{{- $result := slice -}} -{{- if .IsHome -}} - {{ $pages = where .Site.RegularPages "Section" "in" .Site.Params.mainSections }} - {{- $hasPages = true -}} -{{- else if eq .Kind "term" -}} - {{ $pages = .Pages }} - {{- $hasPages = true -}} -{{- else if or (eq .Kind "section") (eq .Kind "taxonomy") -}} - {{ $subsections := .Sections }} - {{ $pages = .Pages | complement $subsections }} - - {{- if eq (len $pages) 0 -}} - {{/* See complete logic in list.html */}} - {{- $pages = $subsections -}} - {{- end -}} - - {{- $hasPages = true -}} +{{- if or .IsHome (eq .Kind "section") (eq .Kind "taxonomy") (eq .Kind "term") -}} + {{- $pages := partial "helper/pages.html" . -}} + {{- $result = .Paginate $pages -}} {{- end -}} -{{- if $hasPages -}} - {{ $pages = .Paginate $pages }} -{{- end -}} - -{{ return $pages }} +{{- return $result -}} diff --git a/layouts/_partials/widget/archives.html b/layouts/_partials/widget/archives.html index e42da27..49c9c69 100644 --- a/layouts/_partials/widget/archives.html +++ b/layouts/_partials/widget/archives.html @@ -9,7 +9,7 @@