Reading time \o/
This commit is contained in:
parent
8501ab391b
commit
099e081eb8
5 changed files with 26 additions and 2 deletions
4
Gemfile
4
Gemfile
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
16
lib/helpers/blog.rb
Normal 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
|
|
@ -14,3 +14,4 @@ include DataHelper
|
|||
include FontAwesomeHelper
|
||||
include ProjectsHelper
|
||||
include SearchHelper
|
||||
include BlogHelper
|
||||
|
|
Loading…
Reference in a new issue