瀏覽代碼

pub widget: Add filter for publication type (Close #217)

George Cushen 7 年之前
父節點
當前提交
48945c6b80

+ 10 - 0
exampleSite/content/home/publications.md

@@ -21,5 +21,15 @@ count = 10
 #   2 = Detailed
 list_format = 0
 
+# Filter by publication type.
+# -1: Any
+#  0: Uncategorized
+#  1: Conference proceedings
+#  2: Journal
+#  3: Work in progress
+#  4: Technical report
+#  5: Book
+#  6: Book chapter
+publication_type = "-1"
 +++
 

+ 10 - 0
exampleSite/content/home/publications_selected.md

@@ -19,5 +19,15 @@ weight = 10
 #   2 = Detailed
 list_format = 2
 
+# Filter by publication type.
+# -1: Any
+#  0: Uncategorized
+#  1: Conference proceedings
+#  2: Journal
+#  3: Work in progress
+#  4: Technical report
+#  5: Book
+#  6: Book chapter
+publication_type = "-1"
 +++
 

+ 8 - 1
layouts/partials/widgets/publications.html

@@ -19,7 +19,14 @@
   <div class="col-xs-12 col-md-8">
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
 
-    {{ range first $page.Params.count (where $.Data.Pages "Type" "publication") }}
+    {{ if and ($page.Params.publication_type) (ne $page.Params.publication_type "-1") }}
+      {{ $.Scratch.Set "recent_pubs" (where (where $.Data.Pages "Type" "publication") ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }}
+    {{ else }}
+      {{ $.Scratch.Set "recent_pubs" (where $.Data.Pages "Type" "publication") }}
+    {{ end }}
+
+    {{ $recent_pubs := $.Scratch.Get "recent_pubs" }}
+    {{ range first $page.Params.count $recent_pubs }}
       {{ if eq $page.Params.list_format 1 }}
         {{ partial "publication_li_classic" . }}
       {{ else if eq $page.Params.list_format 2 }}

+ 9 - 2
layouts/partials/widgets/publications_selected.html

@@ -10,13 +10,20 @@
   <div class="col-xs-12 col-md-8">
     {{ with $page.Content }}<p>{{ . | markdownify }}</p>{{ end }}
 
-    {{ range (where (where $.Data.Pages "Type" "publication") ".Params.selected" true) }}
+    {{ if and ($page.Params.publication_type) (ne $page.Params.publication_type "-1") }}
+      {{ $.Scratch.Set "sel_pubs" (where (where (where $.Data.Pages "Type" "publication") ".Params.selected" true) ".Params.publication_types" "intersect" (slice $page.Params.publication_type)) }}
+    {{ else }}
+      {{ $.Scratch.Set "sel_pubs" (where (where $.Data.Pages "Type" "publication") ".Params.selected" true) }}
+    {{ end }}
+
+    {{ $sel_pubs := $.Scratch.Get "sel_pubs" }}
+    {{ range $sel_pubs }}
       {{ if eq $page.Params.list_format 1 }}
         {{ partial "publication_li_classic" . }}
       {{ else if eq $page.Params.list_format 2 }}
         {{ partial "publication_li_detailed" . }}
       {{ else }}
-          {{ partial "publication_li_simple" . }}
+        {{ partial "publication_li_simple" . }}
       {{ end }}
     {{ end }}