Skip to content
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

Estimated reading time calculation #8011

Closed
BNolet opened this issue Dec 3, 2020 · 6 comments
Closed

Estimated reading time calculation #8011

BNolet opened this issue Dec 3, 2020 · 6 comments

Comments

@BNolet
Copy link

BNolet commented Dec 3, 2020

I would like to be able to modify the calculation on which the estimated reading time is based. Somewhere in the forums I saw that it may be based on 220 words per minute, but I'd like to be able to change that.

@BNolet BNolet added the Proposal label Dec 3, 2020
@davidsneighbour
Copy link
Contributor

davidsneighbour commented Dec 4, 2020

It's easily solvable with some template magic:

https://kodify.net/hugo/strings/reading-time-text/#solution-count-words-then-compute-reading-time

{{ $readTime := mul (div (countwords .Content) 220.0) 60 }}

{{ $minutes := math.Floor (div $readTime 60) }}
{{ $seconds := mod $readTime 60 }}

<p>Reading time: {{ $minutes }} {{ cond (eq $minutes 1) "minute" "minutes" }} and
    {{ $seconds }} {{ cond (eq $seconds 1) "second" "seconds" }}.</p>

Exchange the 220.0 with your number, maybe make it configurable in your config. Note: it MUST end with a point and a digit, so the seconds are calculated properly. (float vs. int)

@BNolet
Copy link
Author

BNolet commented Dec 4, 2020

I'm not asking for a workaround though, I'm asking for this to be a parameter that can be changed in the config.toml file.

@davidsneighbour
Copy link
Contributor

This is not a workaround. It's how reading time is calculated. It's literally a three-line solution you want to use developer and documentation writing time to implement something which is not a core feature of Hugo. There is a reason Hugo has a templating system.

@BNolet
Copy link
Author

BNolet commented Dec 6, 2020

I'm sorry, I was under the impression that this was a feature of hugo that themes took advantage of. Is this something that was previously declined as a feature?

@CarsonSlovoka
Copy link

You can also use the .WordCount or .FuzzyWordCountto helps you.

see more: page-variables

@jmooring jmooring closed this as completed Apr 9, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants