Liquid Jekyll

Photo Credit:

Liquid Jekyll

2 minute read •  •  Posted in  •  Share

Liquid Jekyll - Finding Time :

The Jekyll template this site is based on originally used Jekyll modules to estimate blog post read times. This works great when you are hosting your site using "jekyll serve". Any Jekyll Modules within the _plugins folder can be used to build your site. These ruby-based modules are usually simple to write and work well most of the time.

The Problem :

When you don’t pre-build your site and rely on Github Pages to take your code and turn it into your _site , you end up with a few added restrictions. The biggest of these is Github Pages runs Jekyll with the --safe flag, which inherently disables any 3rd-party modules. This means your lovely _plugins folder gets ignored.

In my case, I want to automatically generate and display how long a post will take an average person to read. The original setup of this Jekyll theme used the following Jekyll Modules to compute the time and display the value.

On the page :

{{ post.content.size | readtime | pluralize: "minute" }} read

read-time.rb :

module ReadTimeFilter
	def readtime(input)
		charcount = 4.5
		wpm = 335
		rt = (input.to_f/charcount/wpm).round
		rt = 1 if rt < 1
	Liquid::Template.register_filter self

pluralize.rb :

module Jekyll
	module Pluralize
		def pluralize(number, singular, plural=nil)
			if number == 1
				"#{number} #{singular}"
			elsif plural == nil
				"#{number} #{singular}s"
				"#{number} #{plural}"

The Solution

As found on , if you are using Liquid templating in your Jekyll build, you can use “Liquid Tags” to achieve a fair amount of logic using inline tags instead of ruby scripts.

On the page :

{{ post.content.size | divided_by:1507 }}  minute read

Other Useful Tidbits :

Till next time,
Jim Howk

Jim Howks-signature