Parcourir la source

posts: Add option to display author names

Close #220
George Cushen il y a 7 ans
Parent
commit
9e65c45d23

+ 3 - 0
archetypes/post.md

@@ -3,6 +3,9 @@ title = "{{ replace .TranslationBaseName "-" " " | title }}"
 date = {{ .Date }}
 draft = false
 
+# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
+authors = []
+
 # Tags and categories
 # For example, use `tags = []` for no tags, or the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
 tags = []

+ 3 - 0
exampleSite/content/post/getting-started.md

@@ -5,6 +5,9 @@ date = 2016-04-20T00:00:00
 lastmod = 2018-01-13T00:00:00
 draft = false
 
+# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
+authors = []
+
 tags = ["academic"]
 summary = "Create a beautifully simple website or blog in under 10 minutes."
 

+ 10 - 0
layouts/partials/article_metadata.html

@@ -2,6 +2,16 @@
 {{ $ := .content }}
 <div class="article-metadata">
 
+  {{ if $.Params.authors }}
+  {{ $authorLen := len $.Params.authors }}
+  <div itemprop="author">
+    {{ range $k, $v := $.Params.authors }}
+      {{- $v -}}
+      {{- if lt $k (sub $authorLen 1) -}}, {{ end }}
+    {{ end }}
+  </div>
+  {{ end }}
+
   <span class="article-date">
     {{ if ne $.Params.Lastmod $.Params.Date }}
         {{ i18n "last_updated" }}