소스 검색

post widget: Add optional simple listing format

See #470
George Cushen 7 년 전
부모
커밋
3eb8355dc8

+ 4 - 0
exampleSite/content/home/posts.md

@@ -20,5 +20,9 @@ tags_exclude = []
 # Number of posts to list.
 count = 5
 
+# List format.
+#   0 = Simple
+#   1 = Detailed
+list_format = 1
 +++
 

+ 5 - 1
exampleSite/content/post/_index.md

@@ -4,9 +4,13 @@ date = 2017-01-01
 math = false
 highlight = false
 
+# List format.
+#   0 = Simple
+#   1 = Detailed
+list_format = 1
+
 # Optional featured image (relative to `static/img/` folder).
 [header]
 image = ""
 caption = ""
-
 +++

+ 0 - 0
layouts/partials/post_li.html → layouts/partials/post_li_detailed.html


+ 6 - 0
layouts/partials/post_li_simple.html

@@ -0,0 +1,6 @@
+{{ $post := .post }}
+
+<div class="pub-list-item" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
+  <i class="fa fa-newspaper-o pub-icon" aria-hidden="true"></i>
+  <a href="{{ $post.Permalink }}" itemprop="url"><span itemprop="headline">{{ $post.Title }}</span></a>
+</div>

+ 10 - 2
layouts/partials/widgets/posts.html

@@ -45,7 +45,11 @@
       {{ $show_post := $.Scratch.Get "show_post" }}
       {{ if ne $show_post "0" }}
         {{ $params := dict "post" . }}
-        {{ partial "post_li" $params }}
+        {{ if eq $page.Params.list_format 0 }}
+          {{ partial "post_li_simple" $params }}
+        {{ else }}
+          {{ partial "post_li_detailed" $params }}
+        {{ end }}
       {{end}}
 
       {{ end }}
@@ -72,7 +76,11 @@
       {{ $show_post := $.Scratch.Get "show_post" }}
       {{ if ne $show_post "0" }}
         {{ $params := dict "post" . }}
-        {{ partial "post_li" $params }}
+        {{ if eq $page.Params.list_format 0 }}
+          {{ partial "post_li_simple" $params }}
+        {{ else }}
+          {{ partial "post_li_detailed" $params }}
+        {{ end }}
       {{end}}
 
       {{ end }}

+ 5 - 1
layouts/section/post.html

@@ -14,7 +14,11 @@
   {{ $paginator := .Paginate .Data.Pages }}
   {{ range $paginator.Pages }}
     {{ $params := dict "post" . }}
-    {{ partial "post_li" $params }}
+    {{ if eq $.Params.list_format 0 }}
+      {{ partial "post_li_simple" $params }}
+    {{ else }}
+      {{ partial "post_li_detailed" $params }}
+    {{ end }}
   {{ end }}
 
   {{ partial "pagination" . }}