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 }}
{{ $posts := where (where $.Data.Pages "Type" "post") ".Params.notonhomepage" nil }}
{{ if $page.Params.tags_include }}
{{ if gt (len $page.Params.tags_include) 0 }}
{{ $posts := where (where (where $.Data.Pages "Type" "post") ".Params.tags" "intersect" $page.Params.tags_include) ".Params.notonhomepage" nil }}
{{ end }}
{{ $.Scratch.Add "show_post" "1" }}
{{ range $post := first $page.Params.count $posts }}
{{ $.Scratch.Add "show_post" "1" }}
{{ 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 and ($page.Params.tags_include) (lt (len .Params.tags) 1) }}
{{ $.Scratch.Set "show_post" "0" }}
{{end}}
{{/* 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 }}
{{/* 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}}
@ -50,6 +48,34 @@
{{ partial "post_li" $params }}
{{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 }}
</div>