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 # Autoprefixing for class
gem 'autoprefixer-rails' gem 'autoprefixer-rails'
# Word counting gem (which takes special characters into account)
# for reading time
gem 'words_counted'
group :development do group :development do
gem 'adsf' gem 'adsf'
gem 'highline' gem 'highline'

View file

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

View file

@ -15,7 +15,8 @@
</h2> </h2>
<% end %> <% end %>
<p class="has-text-centered"> <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> </p>
<hr> <hr>
</div> </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 FontAwesomeHelper
include ProjectsHelper include ProjectsHelper
include SearchHelper include SearchHelper
include BlogHelper