Skip to content

Commit

Permalink
hugo config: add custom word count variable and metadata item
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagowfx committed Jan 14, 2022
1 parent b5e4949 commit cf02321
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ params:
publisherType: Person
showCodeCopyButtons: true
showFullTextinRss: true
showWordCount: true
showReadingTime: true

permalinks:
Expand Down
21 changes: 21 additions & 0 deletions layouts/partials/post_meta.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- $scratch := newScratch }}

{{- if not .Date.IsZero -}}
{{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.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 . "&nbsp;·&nbsp;" -}}
{{- end -}}

0 comments on commit cf02321

Please sign in to comment.