athityakumar / athityakumar.github.io

The profile homepage and blog repository of Athitya Kumar.
https://www.athityakumar.dev/
Other
28 stars 2 forks source link

Add "X minutes read" stamp #8

Open athityakumar opened 7 years ago

athityakumar commented 5 years ago

Reference: https://help.medium.com/hc/en-us/articles/214991667-Read-time

A simple way to calculate would be:

require 'yaml'
READING_SPEED = 265 # Same as Medium

article = YAML.load(File.read("auto/data/posts/#{post_name}.yml"))
words_count = article["html_content"].count(" ")
x_minutes = words_count/READING_SPEED + 1