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
|
# 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'
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
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 FontAwesomeHelper
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
include SearchHelper
|
include SearchHelper
|
||||||
|
include BlogHelper
|
||||||
|
|
Loading…
Reference in a new issue