Reading time in Jekyll

Do you want to display the reading time in your Jekyll’s blog –e.g. like in Medium.com–? Here you have a simple way –without plugins–. First of all we’ve to calculate the reading time dividing the number of words of your page’s content by 180 –assuming that we can read 180 wpm on a monitor–:

{% capture read_time %}
  {{ page.content | number_of_words | divided_by: 180 }}
{% endcapture %}

Then if the read_time variable is equal to 0, we can display 1 just to avoid a 0 min read message:

{% if read_time != '0' %}
  {{ read_time }}
{% else %}
  1
{% endif %} min read

And that’s all. You can put those two snippets of code in your _layouts/post.html file.


 22 February 2014 | tips english