Add reading time to Jekyll without a plugin
You do not need a plugin to show an estimated reading time in Jekyll. Liquid can count the words in a post and divide that number by an assumed reading speed.
This example uses 180 words per minute:
<p>
{% assign words = content | number_of_words %}
{% if words < 360 %}
1 min
{% else %}
{{ words | divided_by: 180 }} mins
{% endif %}
read
</p>
Posts below 360 words show 1 min read. Longer posts use integer division, so the result is deliberately a rough estimate rather than a stopwatch pretending to be precise.
Use page.content if the snippet is in a layout and content is not giving you the expected value. You can also change 180 to match the reading speed you prefer.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- The HTTP Status Codes I Actually Check
A practical guide to common HTTP response codes, redirects, client and server errors, and the headers that explain them.
- What Makes a Website a Progressive Web App?
A practical look at service workers, web app manifests, installation, and the cases where a Progressive Web App is worth building.
- What a Static Site Generator Actually Does
A static site generator combines content and templates before deployment, producing HTML files that a web server can deliver directly.