posts widget: Fix filter in case of multiple instances

This commit is contained in:
George Cushen 2017-09-25 00:15:01 +01:00
commit 9760e0dc2a

View file

@ -22,24 +22,22 @@
{{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }} {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
{{ $posts := where (where $.Data.Pages "Type" "post") ".Params.notonhomepage" nil }} {{ if gt (len $page.Params.tags_include) 0 }}
{{ if $page.Params.tags_include }}
{{ $posts := where (where (where $.Data.Pages "Type" "post") ".Params.tags" "intersect" $page.Params.tags_include) ".Params.notonhomepage" nil }} {{ $posts := where (where (where $.Data.Pages "Type" "post") ".Params.tags" "intersect" $page.Params.tags_include) ".Params.notonhomepage" nil }}
{{ end }}
{{ $.Scratch.Add "show_post" "1" }} {{ $.Scratch.Add "show_post" "1" }}
{{ range $post := first $page.Params.count $posts }} {{ range $post := first $page.Params.count $posts }}
{{ $.Scratch.Set "show_post" "1" }} {{ $.Scratch.Set "show_post" "1" }}
{{/* If `tags_include` is set, exclude posts with no tags. */}} {{/* If `tags_include` is set, exclude posts with no tags. */}}
{{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }} {{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
{{ $.Scratch.Set "show_post" "0" }} {{ $.Scratch.Set "show_post" "0" }}
{{end}} {{end}}
{{/* If `tags_exclude` is set, exclude posts. */}} {{/* If `tags_exclude` is set, exclude posts. */}}
{{ range $key, $val := .Params.tags }} {{ range $key, $val := .Params.tags }}
{{ if in $page.Params.tags_exclude $val }} {{ if in $page.Params.tags_exclude $val }}
{{ $.Scratch.Set "show_post" "0" }} {{ $.Scratch.Set "show_post" "0" }}
{{end}} {{end}}
{{end}} {{end}}
@ -50,6 +48,34 @@
{{ partial "post_li" $params }} {{ partial "post_li" $params }}
{{end}} {{end}}
{{ end }}
{{ else}}
{{ $posts := where (where $.Data.Pages "Type" "post") ".Params.notonhomepage" nil }}
{{ $.Scratch.Add "show_post" "1" }}
{{ range $post := first $page.Params.count $posts }}
{{ $.Scratch.Set "show_post" "1" }}
{{/* If `tags_include` is set, exclude posts with no tags. */}}
{{ if and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
{{ $.Scratch.Set "show_post" "0" }}
{{end}}
{{/* If `tags_exclude` is set, exclude posts. */}}
{{ range $key, $val := .Params.tags }}
{{ if in $page.Params.tags_exclude $val }}
{{ $.Scratch.Set "show_post" "0" }}
{{end}}
{{end}}
{{ $show_post := $.Scratch.Get "show_post" }}
{{ if ne $show_post "0" }}
{{ $params := dict "post" . "page" $page }}
{{ partial "post_li" $params }}
{{end}}
{{ end }}
{{ end }} {{ end }}
</div> </div>