refactor: use .Params.mainSections to filter posts
It's recommended by Hugo's official doc: https://gohugo.io/functions/where/#mainsections
This commit is contained in:
parent
47fb5af201
commit
e176e29811
@ -9,7 +9,7 @@ title = "Example Site"
|
|||||||
page = "/:slug/"
|
page = "/:slug/"
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
postSection = "post"
|
mainSections = ["post"]
|
||||||
favicon = ""
|
favicon = ""
|
||||||
[params.sidebar]
|
[params.sidebar]
|
||||||
emoji = "🍥"
|
emoji = "🍥"
|
||||||
|
@ -4,11 +4,10 @@
|
|||||||
{{ partialCached "sidebar/left.html" . }}
|
{{ partialCached "sidebar/left.html" . }}
|
||||||
|
|
||||||
<main class="main full-width">
|
<main class="main full-width">
|
||||||
{{ $postSection := $.Site.Params.postSection }}
|
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||||
{{ $v1 := where .Site.RegularPages "Section" $postSection }}
|
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
||||||
{{ $v2 := where .Site.RegularPages "Params.hidden" "!=" true }}
|
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||||
{{ $.Scratch.Set "filtered" ($v1 | intersect $v2) }}
|
{{ $pag := .Paginate ($filtered) }}
|
||||||
{{ $pag := .Paginate ($.Scratch.Get "filtered") }}
|
|
||||||
|
|
||||||
<section class="article-list">
|
<section class="article-list">
|
||||||
{{ range $index, $element := $pag.Pages }}
|
{{ range $index, $element := $pag.Pages }}
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ $postSection := $.Site.Params.postSection }}
|
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||||
{{ $v1 := where .Site.RegularPages "Section" $postSection }}
|
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
||||||
{{ $v2 := where .Site.RegularPages "Params.hidden" "!=" true }}
|
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||||
{{ $filtered := $v1 | intersect $v2 }}
|
|
||||||
{{ range $filtered.GroupByDate "2006" }}
|
{{ range $filtered.GroupByDate "2006" }}
|
||||||
{{ $id := lower (replace .Key " " "-") }}
|
{{ $id := lower (replace .Key " " "-") }}
|
||||||
<div class="archive-group" id="{{ $id }}">
|
<div class="archive-group" id="{{ $id }}">
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
{{- $authorName := .Site.Author.name -}}
|
{{- $authorName := .Site.Author.name -}}
|
||||||
|
|
||||||
{{- if .IsHome -}}
|
{{- if .IsHome -}}
|
||||||
{{- $v1 := where .Site.RegularPages "Type" "post" -}}
|
{{ $pages := where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
|
||||||
{{- $v2 := where .Site.RegularPages "Params.hidden" "!=" true -}}
|
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
||||||
{{- $filtered := $v1 | intersect $v2 -}}
|
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||||
{{- $pag := .Paginate ($filtered) -}}
|
{{ $pag := .Paginate ($filtered) }}
|
||||||
{{ if .Paginator.HasPrev }}{{ .Paginator }} - {{ end }}{{ $siteTitle }}
|
{{ if .Paginator.HasPrev }}{{ .Paginator }} - {{ end }}{{ $siteTitle }}
|
||||||
{{- else if eq .Kind "term" -}}
|
{{- else if eq .Kind "term" -}}
|
||||||
{{- $pag := .Paginate (where .Data.Pages "Type" "post") -}}
|
{{- $pag := .Paginate (where .Data.Pages "Type" "post") -}}
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<h1 class="widget-title">Archive</h1>
|
<h1 class="widget-title">Archive</h1>
|
||||||
|
|
||||||
{{ $v1 := where .Site.RegularPages "Section" "post" }}
|
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||||
{{ $v2 := where .Site.RegularPages "Params.hidden" "!=" true }}
|
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
||||||
{{ $filtered := $v1 | intersect $v2 }}
|
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||||
{{ $archive := $filtered.GroupByDate "2006" }}
|
{{ $archive := $filtered.GroupByDate "2006" }}
|
||||||
|
|
||||||
{{ range first .Site.Params.widgets.archive.limit ($archive) }}
|
{{ range first .Site.Params.widgets.archive.limit ($archive) }}
|
||||||
|
Loading…
Reference in New Issue
Block a user