Skip to content

Instantly share code, notes, and snippets.

@deomorxsy
Last active August 17, 2019 22:38
Show Gist options
  • Save deomorxsy/8dd6c2bd18744e16ce55d7d53f97cec0 to your computer and use it in GitHub Desktop.
Save deomorxsy/8dd6c2bd18744e16ce55d7d53f97cec0 to your computer and use it in GitHub Desktop.

Reading time in Liquid (for Jekyll)

HTML and Liquid syntax INSIDE the _includes folder

source: https://carlosbecker.com/posts/jekyll-reading-time-without-plugins/

We can estimate the reading time with the measure called Words per Minute (WPM). According to Wikipedia, an average person can read 180 words per minute in a computer monitor. 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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment