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

Reading time helper #9200

Closed
ErisDS opened this issue Nov 2, 2017 · 1 comment · Fixed by #9217
Closed

Reading time helper #9200

ErisDS opened this issue Nov 2, 2017 · 1 comment · Fixed by #9217
Assignees
Labels
feature [triage] New features we're planning or working on

Comments

@ErisDS
Copy link
Member

ErisDS commented Nov 2, 2017

A common feature on publications nowadays is an indication of how long content will take to read.

This is usually based on a word count divided by an average reading rate, with some modifier based on the number of images.

A good reference is: https://blog.medium.com/read-time-and-you-bc2048ab620c
jQuery plugin as ref: https://github.com/michael-lynch/reading-time (this requires the content to be on the page)

These things all pretty much assume English, but should work okish for other latin languages.

For now (v1):

  • Word count: can be calculated from the content (see Ghost-Admin's version
  • image count: use 1 if there's a featured image for the post, 0 if not
  • average reading rate: 275, hardcoded

Implementation should live in the theme layer, e.g. we only do this calculation when the reading time helper is used. If we find more use cases for including statistics, we can do more of this at the API layer & optimise how it works later.

  • The helper itself should be {{reading_time}}.
  • It must work in post listings as well as on the post page, i.e. when the content isn't written out anywhere.

Thanks to @erikstern-r7 for the use case & reference material.


Potential improvements for later include:

  • Grab the real number of images
  • Allow the reading rate to be configured
  • Allow word count function to be replaced for other languages

Got a use case for themes? If you have a use case that you can't solve with the existing theme tools, please come tell us about it in #themes.

@ErisDS ErisDS added feature [triage] New features we're planning or working on themes labels Nov 2, 2017
aileen added a commit to aileen/Ghost that referenced this issue Nov 6, 2017
closes TryGhost#9200

- Registered new server helper `{{reading_time}}`.
- Added new global util `word-count` based on the util in Ghost admin, which returns the number of words in an HTML string.
- Based on the word count of the post html, the helper calculated the estimated reading time:
   - 275 words per minute
   - additional 12 seconds when post has feature image
- Renders a string like 'x min red', unless reading time is less than a minute. In this case, the rendered string is '< 1 min read'.
ErisDS pushed a commit that referenced this issue Nov 6, 2017
closes #9200

- Registered new server helper `{{reading_time}}`.
- Added new global util `word-count` based on the util in Ghost admin, which returns the number of words in an HTML string.
- Based on the word count of the post html, the helper calculated the estimated reading time:
   - 275 words per minute
   - additional 12 seconds when post has feature image
- Renders a string like 'x min red', unless reading time is less than a minute. In this case, the rendered string is '< 1 min read'.
@aileen aileen added later [triage] Things we intend to work but are not immediate priority and removed in review labels Nov 7, 2017
@aileen
Copy link
Member

aileen commented Nov 7, 2017

I added the later label, to keep in mind, that we still wanna build a v2 for it:

Potential improvements for later include:

  • Grab the real number of images
  • Allow the reading rate to be configured
  • Allow word count function to be replaced for other languages

kirrg001 pushed a commit that referenced this issue Mar 5, 2018
refs #9200

- We have not yet counted the images within your html, this commit counts images based on the this algorithm: https://blog.medium.com/read-time-and-you-bc2048ab620c
- Added imageCount utility, which counts images using an img-tag regex, amended from the general tag-regex found in wordCount
- Added this imageCount to the {{reading_time}} helper, adding 12 seconds to the reading time for every image
- The feature image is still counted as before
- The first image adds 12 seconds, the second 11, the third 10, and so on
- Images from the tenth onwards add 3 seconds to the reading time
@ErisDS ErisDS removed later [triage] Things we intend to work but are not immediate priority labels Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature [triage] New features we're planning or working on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants