Skip to content

Improve how the reading time is displayed #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pagination.pagerSize = 5
title = "Terminal"

[languages.en.params]
# readingSpeed = 212 # in words per minute, default is 212
subtitle = "A simple, retro theme for Hugo"
owner = ""
keywords = ""
Expand All @@ -243,8 +244,11 @@ pagination.pagerSize = 5
olderPosts = "Older posts"
missingContentMessage = "Page not found..."
missingBackButtonLabel = "Back to home page"
minuteReadingTime = "min read"
words = "words"
word = "word"
minute = "minute"
minutes = "minutes"
to_read = "to read"

[languages.en.params.logo]
logoText = "Terminal"
Expand Down
5 changes: 3 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ <h1 class="post-title">
{{- with .Params.Author -}}
<span class="post-author">{{ . }}</span>
{{- end -}}
{{- if and (.Param "readingTime") (eq (.Param "readingTime") true) -}}
<span class="post-reading-time">{{ .ReadingTime }} {{ $.Site.Params.minuteReadingTime | default "min read" }} ({{ .WordCount }} {{ $.Site.Params.words | default "words" }})</span>
{{- if and (.Param "readingTime") (eq (.Param "readingTime") true) -}}{{ $customReadingTime := div (float .WordCount) (.Site.Params.readingSpeed | default 212) }}{{ $customReadingTime = math.Ceil $customReadingTime }}<!--
(browsers insert spaces (here) sometimes)
--><span class="post-reading-time">{{ $customReadingTime }} {{ if eq $customReadingTime 1.0 }}{{ $.Site.Params.minute | default "minute" }}{{ else }}{{ $.Site.Params.minutes | default "minutes" }}{{ end }} {{ $.Site.Params.to_read | default "to read" }} ({{ .WordCount }} {{ if eq .WordCount 1 }}{{ $.Site.Params.word | default "word" }}{{ else }}{{ $.Site.Params.words | default "words" }}{{ end }})</span>
{{- end -}}
</div>

Expand Down