Procházet zdrojové kódy

posts widget: Fix filter in case of multiple instances

George Cushen před 7 roky
rodič
revize
9760e0dc2a
1 změnil soubory, kde provedl 38 přidání a 12 odebrání
  1. 38 12
      layouts/partials/widgets/posts.html

+ 38 - 12
layouts/partials/widgets/posts.html

@@ -22,24 +22,49 @@
 
     {{ 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" }}
+        {{/* 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}}
 
-      {{/* If `tags_exclude` is set, exclude posts. */}}
-      {{ range $key, $val := .Params.tags }}
-        {{ if in $page.Params.tags_exclude $val }}
+      {{ 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}}
@@ -50,6 +75,7 @@
         {{ partial "post_li" $params }}
       {{end}}
 
+      {{ end }}
     {{ end }}
 
   </div>