jekyll-smart-reading-time
jekyll-smart-reading-time strips code blocks before it counts words, so the reading time is accurate.
Open Source Plugin ∙

jekyll-smart-reading-time

A Jekyll plugin that estimates reading time after stripping out code blocks, HTML, and Liquid tags, so only the prose gets counted.

jekyll-smart-reading-time works out reading time for Jekyll posts the right way. The old, abandoned gem counts every character on the page, including code blocks, HTML tags, and Liquid template syntax. So a post full of code examples looks like a 20-minute read when the prose takes 3 minutes. This plugin strips all of that out before it counts.

What Gets Stripped

Before counting words, the plugin removes:

  • Fenced code blocks ( ` ... ` )
  • Indented code blocks (4+ space lines)
  • HTML tags
  • Liquid tags ({% %} and {{ }})
  • YAML frontmatter

Then it counts what’s left at 238 WPM (a research-backed average for adult reading speed) and puts the result in page.reading_time. The minimum is 1 minute.

Installation

Add to your Gemfile:

gem "jekyll-smart-reading-time"

Add to plugins: in _config.yml:

plugins:
  - jekyll-smart-reading-time

Template Usage

Every post and page gets page.reading_time (an integer) with no extra setup:

<span>{{ page.reading_time }} min read</span>

Or drop the optional Liquid tag anywhere in your content:

{% reading_time %}

That renders as 3 min read.

Configuration

To change the default reading speed:

reading_time:
  wpm: 200  # default: 238

Source

Available on GitHub and RubyGems.

gem install jekyll-smart-reading-time