Skip to content

Instantly share code, notes, and snippets.

@seanislegend
Forked from zachleat/reading_time.rb
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanislegend/0d37f3febc41d6b4bf2d to your computer and use it in GitHub Desktop.
Save seanislegend/0d37f3febc41d6b4bf2d to your computer and use it in GitHub Desktop.
# Outputs the reading time
# "A 4 minute read"
# Put into your _plugins dir in your Jekyll site
# Usage: A {{ page.content | reading_time }} read
module ReadingTimeFilter
def reading_time( input )
words_per_minute = 180
words = input.split.size;
minutes = ( words / words_per_minute ).floor
minutes = "#{minutes} minute"
end
end
Liquid::Template.register_filter(ReadingTimeFilter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment