• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Ruby
  • License
    ISC License
  • Created about 11 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Liquid filter to estimate how long a passage of text will take to read.

reading_time

A Liquid filter that intelligently counts the number of words in a piece of HTML and estimates how long the text will take to read.

Installation

The easiest way to install this plugin is with RubyGems: gem install liquid_reading_time.

If you’re using Jekyll, see the Jekyll documentation on installing plugins for more-detailed installation instructions. This plugin requires Nokogiri, so if you install this one manually you’ll need to make sure that that one is installed too.

Usage

Two functions are provided:

  • reading_time

    This function gives an estimate of the amount of time it will take to read the input text. The return value is an integer number of minutes. The input should be HTML (i.e. the text should have already been run through your Markdown or Textile filter). For example, you could use it in a _layout file like this:

      {% capture time %}{{ content | reading_time }}{% endcapture %}
      <p>This article will take {{ time }} {% if time == '1' %}minute{% else %}minutes{% endif %} to read.</p>
    

    Even better, using the pluralize filter,

      <p>This article will take {{ content | reading_time | pluralize: "minute" }} to read.</p>
    
  • count_words

    This function returns the number of words in the input. Like reading_time, this function takes HTML as its input.

Details

These functions try to be smart about counting words. Specifically, words are not counted if they are contained within any of the following HTML elements: area, audio, canvas, code, embed, footer, form, img, map, math, nav, object, pre, script, svg, table, track, and video. My intention here is to prevent words from contributing toward the count if they don’t seem to be part of the running text—contrast this with the simple but inaccurate approach of e.g. Jekyll’s built-in number_of_words.

The plugin assumes a reading speed of 270 words per minute. Wikipedia cites 250–300 words per minute as a typical range, and I found that I could read articles on my website at about 270 words per minute.

Author

This plugin was created by Benjamin Esham.

This project is hosted on GitHub. Please feel free to submit pull requests.

Version history

The version numbers of this project conform to Semantic Versioning 2.0.

  • 1.1.3 (2017-07-19)
    • Updated the dependencies to reflect that the plugin works with Liquid 4 (without any code changes needed).
  • 1.1.2 (2015-03-07)
    • Apostrophes and curly single quotes shouldn’t break words into two.
    • This plugin works with Liquid 3.x in addition to 2.x; updated the dependencies to reflect that.
    • Added unit tests.
  • 1.1.1 (2015-03-04)
    • Don’t put the ReadingTime module in the Jekyll module.
    • Packaged the plugin as a Gem.
  • 1.1.0 (2013-08-30)
    • Switched from REXML to Nokogiri for HTML parsing.
    • Input can now be HTML or XHTML. Previously, only valid XML was accepted (so things like non-closed img tags would make reading_time crash).
    • Character entities like &#x8617; are no longer included in the word count.
  • 1.0.0 (2013-08-24): Changed reading speed from 220 to 270 words per minute.
  • 0.9.0 (2013-08-19): Initial release.

License

Copyright © 2013, 2015, 2017 Benjamin D. Esham. This program is released under the ISC license, which you can find in the file LICENSE.md.

More Repositories

1

chrome-export

Python scripts to convert Google Chrome’s bookmarks and history to the standard HTML-ish bookmarks file format.
Python
190
star
2

pinboard-notes-backup

Back up the notes you’ve saved to Pinboard
Haskell
81
star
3

zenburn-terminal

An adaptation of the Zenburn color scheme for the OS X Terminal app
59
star
4

inline_highlight

A tag for inline syntax highlighting in Jekyll.
Ruby
29
star
5

pluralize

A Liquid filter to make it easy to form correct plurals.
Ruby
29
star
6

the-hacker-crackdown

An ebook of “The Hacker Crackdown: Law and Disorder on the Electronic Frontier” by Bruce Sterling
HTML
26
star
7

clj-plist

A property list (.plist) parser for Clojure
HTML
11
star
8

simple-queue

Process a queue of tasks, pausing after each one
HTML
8
star
9

clj-schulze

A Clojure implementation of the Schulze voting method
Clojure
8
star
10

biogoo

A color scheme for Vim with colorful text on a light gray background.
Vim Script
7
star
11

hitting-set

A Clojure library to find hitting sets and set covers
HTML
6
star
12

microformats2-on-a-map

A web application to extract microformats2-formatted locations from webpages and display them on a map
JavaScript
4
star
13

py-pinboard2html

A Python script to convert your Pinboard bookmarks into an HTML bookmarks file
Python
2
star
14

x-sistemo-widget

A simple Dashboard widget to convert between the X-system and Unicode for Esperanto text.
JavaScript
1
star
15

py-abemails

A Python script to extract all e-mail addresses from the Mac OS X address book
Python
1
star
16

cu-busboard

A slick Dashboard widget to tell you when your CUMTD bus is coming.
JavaScript
1
star