Here’s a small snippet of Liquid Markup , to be used with Jekyll , for determining the time to read for a post. It’s not perfect, but it works. You could make it into a plugin and drop it in the _plugins
folder or, just copy paste it into the layout
of your choice, for e.g. the post
layout.
Using the snippet within the layout makes more sense, if you are hosting your blog with Github Pages .
1 {% capture count_words %}
2 {{ page.content | number_of_words }}
3 {% endcapture %}
4
5 {% capture time_words %}
6 {{count_words | divided_by: 5}}
7 {% endcapture %}
8
9 {{count_words}} Words in Post.
10 Reading Time: ~ {{time_words | divided_by: 60}} min. or so.
Explanation:
Line 1:
We use the capture
block tag to, store / capture (assign) the value returned from Line 2.
Line 2:
Essentially counts the number of words in post/page, using the number_of_words
filter. This filter is available to be used freely, from within jekyll itself.
Line 5:
We use the capture
block tag to, store / capture (assign) the value returned from Line 6.
Line 6:
We use the captured value, stored in the variable count_words
and divide it by 5. This value is then stored in the variable time_words
We divide it by 5, because the average individual reads about 250-300 words a minute 1. The average of 250 and 300 us about 275 words per minute. If we divide that by 60 (60 seconds = 1 minute), we get around 4.583 words per seconds. I’ve rounded that off to 5. If you want to, you can stick with 4.5 or 4.58.
Line 9:
We output the no. of words in the post.
Line 10:
We divide the no of words read / per second, by 60. And output the value. The division will round off the decimals and, give you the number of minutes required for reading the post.