ReadingTime Define

Here’s the partial I use:

{{ if gt .ReadingTime 1 }}
    {{ .Scratch.Set "readingTime" "minutes" }}
{{ else }}
    {{ .Scratch.Set "readingTime" "minute" }}
{{ end }}

<p>Reading time: {{ .ReadingTime }} {{ .Scratch.Get "readingTime" }}</p>

{{/*<!-- NOTE: Alternative writing:
    {{ $readTime := cond (gt .ReadingTime 1) "minutes" "minute" }}
    <p>Reading time: {{ .ReadingTime }} {{ $readTime }}.</p>
-->*/}}

Hope this helps.

4 Likes