Jekyll Snippets (Tips 'n' Tricks) Series
Welcome. The Jekyll Snippets chapter collects tips 'n' tricks about all thinks Jekyll and friends. Do you have any Jekyll tips or tricks that you'd like to write about? We love guest posts. Send in a pull request or open an issue ticket to get the conversation started and your write-up posted on Planet Jekyll.
Reading Time (e.g. 3 mins) with _includes/reading_time.html Template
To add the reading time (e.g. 3 mins) to your posts include the reading_time.html
template in your post layout. Example:
{% include reading_time.html %}
_includes/reading_time.html
:
<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>
Note: The template assumes a reading speed of 180 words per minute (WPM).
Sources
- Jekyll: Reading time without plugins by Carlos Becker, Jan 2015
- Wikipedia: Words per minute