Browse Source

Add optional reading time/word count indication

via PR #134 @looer

Added config variable so this doesn't show up

Show "reading time" and "word count" but only if one of the following are true:
1) A global config `params` value is set `show_reading_time = true`
 2) A section front matter value is set `show_reading_time = true`
3) A page front matter value is set `show_reading_time = true`
tags/2.34
budparr 6 years ago
parent
commit
fd22513cf1
No account linked to committer's email address
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      layouts/_default/single.html

+ 12
- 1
layouts/_default/single.html View File

{{ end }} {{ end }}


{{ define "main" }} {{ define "main" }}
{{ $section := .Site.GetPage "section" .Section }}
<article class="flex-l flex-wrap justify-between mw8 center ph3 ph0-l"> <article class="flex-l flex-wrap justify-between mw8 center ph3 ph0-l">


<header class="mt4 w-100"> <header class="mt4 w-100">
{{/* Hugo uses Go's date formatting is set by example. Here are two formats */}} {{/* Hugo uses Go's date formatting is set by example. Here are two formats */}}
<time class="f6 mv4 dib tracked" datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}"> <time class="f6 mv4 dib tracked" datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{- .Date.Format "January 2, 2006" -}} {{- .Date.Format "January 2, 2006" -}}
</time>
</time>
{{/*
Show "reading time" and "word count" but only if one of the following are true:
1) A global config `params` value is set `show_reading_time = true`
2) A section front matter value is set `show_reading_time = true`
3) A page front matter value is set `show_reading_time = true`
*/}}
{{ if (or (eq (.Param "show_reading_time") true) (eq $section.Params.show_reading_time true) )}}
<span class="f6 mv4 dib tracked"> - {{ .ReadingTime}} minutes read</span>
<span class="f6 mv4 dib tracked"> - {{ .WordCount}} words</span>
{{ end }}
</header> </header>


<main class="nested-copy-line-height lh-copy serif f4 nested-links nested-img mid-gray pr4-l w-two-thirds-l"> <main class="nested-copy-line-height lh-copy serif f4 nested-links nested-img mid-gray pr4-l w-two-thirds-l">

Loading…
Cancel
Save