refactor: centralize page filtering logic, and allow sort by lastmod (#1250)
* refactor: migrate page visibility control from `Params.hidden` to the new `build.list` parameter. * refactor: centralize page filtering logic into a new `helper/pages.html` partial * feat: introduce `SortBy` parameter to enable sorting pages by last modified date * refactor: extract page sorting logic into a new `pages-sort.html` partial
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{{- $pages := .Pages -}}
|
||||
|
||||
{{- if eq .Context.Site.Params.SortBy "lastmod" -}}
|
||||
{{- $pages = $pages.ByLastmod.Reverse -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- return $pages -}}
|
||||
@@ -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 -}}
|
||||
@@ -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 -}}
|
||||
|
||||
Reference in New Issue
Block a user