Reading time with Liquid (for jekyll)

PS: HTML and Liquid syntax INSIDE the _includes folder

We can estimate the reading time with the measure called Words per Minute, (WPM). An average person can read 180 words per minute in a computer monitor1. So, we can include this in our blog post layout with one of these hibrid snippets between HTML (to style with CSS later) and Liquid:

<span class="reading-time" title="Estimated read time">
  {% assign words = content | number_of_words %}
  {% if words < 360 %}
    1 min
  {% else %}
    {{ words | divided_by:180 }} mins
  {% endif %}
</span>

or, if you want to be more accurate:


{% assign words = content | number_of_words %}
  {% if words < 270 %}
    1 minute
  {% else %}
    {{ words | divided_by:135 }} minutes
  {% endif %}

You can call it with


{% include read_time.html %}


References:

  1. WPM