Reading time \o/

This commit is contained in:
Lorin Werthen 2016-11-06 17:45:30 +01:00
parent 8501ab391b
commit 099e081eb8
No known key found for this signature in database
GPG key ID: F11FFC921E0E08E0
5 changed files with 26 additions and 2 deletions

View file

@ -19,6 +19,10 @@ gem 'therubyracer'
# Autoprefixing for class
gem 'autoprefixer-rails'
# Word counting gem (which takes special characters into account)
# for reading time
gem 'words_counted'
group :development do
gem 'adsf'
gem 'highline'

View file

@ -79,6 +79,7 @@ GEM
w3c_validators (1.2)
json
nokogiri
words_counted (1.0.2)
PLATFORMS
ruby
@ -97,6 +98,7 @@ DEPENDENCIES
terminal-notifier-guard
therubyracer
w3c_validators
words_counted
BUNDLED WITH
1.13.3
1.13.6

View file

@ -15,7 +15,8 @@
</h2>
<% end %>
<p class="has-text-centered">
<small>Created at <%= item[:created_at] %></small>
<small>Geschreven op <%= item[:created_at] %></small><br>
Leestijd: <%= reading_time @item %>
</p>
<hr>
</div>

16
lib/helpers/blog.rb Normal file
View file

@ -0,0 +1,16 @@
require 'words_counted'
module BlogHelper
def reading_time(blogpost)
human_wpm = 200.0
words = WordsCounted.count(blogpost.reps[:text].compiled_content).token_count
minutes = (words / human_wpm).ceil
if minutes == 1
"#{minutes} minuut"
else
"#{minutes} minuten"
end
end
end

View file

@ -14,3 +14,4 @@ include DataHelper
include FontAwesomeHelper
include ProjectsHelper
include SearchHelper
include BlogHelper