From 9760e0dc2af2eb3fa5f25697a0d1859d6d7b229c Mon Sep 17 00:00:00 2001 From: George Cushen Date: Mon, 25 Sep 2017 00:15:01 +0100 Subject: [PATCH] posts widget: Fix filter in case of multiple instances --- layouts/partials/widgets/posts.html | 52 +++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/layouts/partials/widgets/posts.html b/layouts/partials/widgets/posts.html index 4e9ef090..87421369 100644 --- a/layouts/partials/widgets/posts.html +++ b/layouts/partials/widgets/posts.html @@ -22,24 +22,22 @@ {{ with $page.Content }}

{{ . | markdownify }}

{{ 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 }}