From 0f64a4206a109e4643aca07772d6091f9607068c Mon Sep 17 00:00:00 2001 From: tdro Date: Tue, 6 Dec 2022 23:43:53 -0500 Subject: themes/default/layouts/partials: Consolidate the content filter into a function --- themes/default/layouts/_default/index.json | 4 +--- themes/default/layouts/_default/rss.xml | 9 +++++---- themes/default/layouts/_default/sitemap.xml | 4 +--- themes/default/layouts/partials/function-filters-content.html | 10 ++++++++++ 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 themes/default/layouts/partials/function-filters-content.html diff --git a/themes/default/layouts/_default/index.json b/themes/default/layouts/_default/index.json index 7cfd37d..6cbc1ef 100644 --- a/themes/default/layouts/_default/index.json +++ b/themes/default/layouts/_default/index.json @@ -7,9 +7,7 @@ "next_url": "{{ .URL | absURL }}", {{- end }} "items": [ - {{- $notExpired := where .Paginator.Pages "Params.expirydate" "eq" nil -}} - {{- $notUnlisted := where .Paginator.Pages "Params.unlisted" "eq" nil -}} - {{- $filteredPages := $notExpired | intersect $notUnlisted -}} + {{- $filteredPages := partial "function-filters-content.html" .Paginator.Pages -}} {{- range $index, $data := $filteredPages -}} {{- if and $index (gt $index 0) -}},{{- end }} { diff --git a/themes/default/layouts/_default/rss.xml b/themes/default/layouts/_default/rss.xml index 8248cc1..01f2aa6 100644 --- a/themes/default/layouts/_default/rss.xml +++ b/themes/default/layouts/_default/rss.xml @@ -52,6 +52,8 @@ {{- end -}} {{- end -}} +{{- $filteredPages := partial "function-filters-content.html" .Paginator.Pages -}} + {{- printf `` | safeHTML }} {{ printf `` | safeHTML }} @@ -77,7 +79,7 @@ {{ $atomPrevious }} {{ $atomNext }} - {{ range first $limit .Paginator.Pages }} + {{ range first $limit $filteredPages -}} {{- $author = partial "function-authors-data.html" . -}} {{- $profile = $author.picture.profile -}} @@ -104,7 +106,6 @@ {{- $atomAuthorUri = .Params.Feed.favicon | absURL -}} {{- end -}} - {{ if and (not .Params.Unlisted) (not .ExpiryDate) }} {{ .Summary | htmlUnescape }} {{ .Permalink }} @@ -120,7 +121,7 @@ {{ $atomAuthorUri }} - {{ end -}} - {{ end }} + + {{ end -}} diff --git a/themes/default/layouts/_default/sitemap.xml b/themes/default/layouts/_default/sitemap.xml index b751f65..fdbc045 100644 --- a/themes/default/layouts/_default/sitemap.xml +++ b/themes/default/layouts/_default/sitemap.xml @@ -9,9 +9,7 @@ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" > - {{- $notExpired := where .Data.Pages "Params.expirydate" "eq" nil -}} - {{- $notUnlisted := where .Data.Pages "Params.unlisted" "eq" nil -}} - {{- $filteredPages := $notExpired | intersect $notUnlisted -}} + {{- $filteredPages := partial "function-filters-content.html" .Data.Pages -}} {{- range $filteredPages }} {{- with .Sitemap.ChangeFreq -}} diff --git a/themes/default/layouts/partials/function-filters-content.html b/themes/default/layouts/partials/function-filters-content.html new file mode 100644 index 0000000..8ebad51 --- /dev/null +++ b/themes/default/layouts/partials/function-filters-content.html @@ -0,0 +1,10 @@ +{{- $input := . -}} + +{{- $notExpired := where $input "Params.expirydate" "eq" nil -}} +{{- $notUnlisted := where $input "Params.unlisted" "eq" nil -}} + +{{- $filteredPages := $notExpired | intersect $notUnlisted -}} + +{{- $output := $filteredPages -}} + +{{- return $output -}} -- cgit v1.2.3