Skip to content

Instantly share code, notes, and snippets.

@milanaryal
Last active March 23, 2020 22:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milanaryal/c20770efdb34809c8d48 to your computer and use it in GitHub Desktop.
Save milanaryal/c20770efdb34809c8d48 to your computer and use it in GitHub Desktop.
Reading time on Jekyll
{% comment %}
prints friendly human readable reading time
divided_by doesn't round, so assuming 180 WPM we use:
<90 = 30 seconds
<270 = 1 minute
<450 = 2 minutes
<630 = 3 minutes
<810 = 4 minutes
<990 = 5 minutes
{% endcomment %}
{% assign words = content | number_of_words %}
{% if words <= 90 %}
{% assign reading_time = "30 sec" %}
{% elsif words < 270 %}
{% assign reading_time = "1 min" %}
{% elsif words < 450 %}
{% assign reading_time = "2 min" %}
{% elsif words < 630 %}
{% assign reading_time = "3 min" %}
{% elsif words < 810 %}
{% assign reading_time = "4 min" %}
{% elsif words < 990 %}
{% assign reading_time = "5 min" %}
{% else %}
{% assign reading_time = words | divided_by:180 | append:" min" %}
{% endif %}
{{ reading_time }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment