Skip to content

Instantly share code, notes, and snippets.

@juev
Forked from zachleat/reading_time.rb
Last active August 29, 2015 14:24
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 juev/2e128555b606d964d442 to your computer and use it in GitHub Desktop.
Save juev/2e128555b606d964d442 to your computer and use it in GitHub Desktop.
# Outputs the reading time
# Read this in “about 4 minutes”
# Put into your _plugins dir in your Jekyll site
# Usage: Read this in about {{ page.content | reading_time }}
module ReadingTimeFilter
def reading_time( input )
words_per_minute = 180
words = input.split.size;
minutes = ( words / words_per_minute ).floor
minutes_label = minutes === 1 ? " minute" : " minutes"
minutes > 0 ? "about #{minutes} #{minutes_label}" : "less than 1 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