From cf023216d3f8cef8957f3a98b2a92d575a521583 Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Fri, 14 Jan 2022 17:45:30 -0500 Subject: [PATCH] hugo config: add custom word count variable and metadata item --- config.yml | 1 + layouts/partials/post_meta.html | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 layouts/partials/post_meta.html diff --git a/config.yml b/config.yml index 6318f80a..02bb4f0a 100644 --- a/config.yml +++ b/config.yml @@ -80,6 +80,7 @@ params: publisherType: Person showCodeCopyButtons: true showFullTextinRss: true + showWordCount: true showReadingTime: true permalinks: diff --git a/layouts/partials/post_meta.html b/layouts/partials/post_meta.html new file mode 100644 index 00000000..ef1e52dc --- /dev/null +++ b/layouts/partials/post_meta.html @@ -0,0 +1,21 @@ +{{- $scratch := newScratch }} + +{{- if not .Date.IsZero -}} +{{- $scratch.Add "meta" (slice (printf "%s" (.Date) (.Date.Format (default "January 2, 2006" .Site.Params.DateFormat)))) }} +{{- end }} + +{{- if (.Param "ShowReadingTime") -}} +{{- $scratch.Add "meta" (slice (i18n "read_time" .ReadingTime | default (printf "%d min" .ReadingTime))) }} +{{- end }} + +{{- if (.Param "ShowWordCount") -}} +{{- $scratch.Add "meta" (slice (i18n "words" .WordCount | default (printf "%d words" .WordCount))) }} +{{- end }} + +{{- with (partial "author.html" .) }} +{{- $scratch.Add "meta" (slice .) }} +{{- end }} + +{{- with ($scratch.Get "meta") }} +{{- delimit . " ยท " -}} +{{- end -}}