Reading time

:  ~ 45 sec read

I always wanted to add this to my posts, but never really got to do it. As usual, this was also easier than expected. I'm surely using some bad practices, but it got the job done.

I installed the readtime gem, and added some HTML:

<% reading_time = content.reading_time(format: :approx)
   if reading_time.to_s['seconds']
     reading_time = '1 min'
   else
     reading_time = reading_time.gsub!('minutes', 'min')
   end
-%>
<%- if (published_at = Time.at(date)) -%>
  <h4>
    <time datetime="<%= published_at.strftime('%B %e, %Y') -%>">
      <%= published_at.strftime('%b %e, %Y') -%>
    </time>
    <%= "- #{reading_time} read" -%>
  </h4>
<%- else -%>
  <h4>
    <%= "#{reading_time} read" -%>
  </h4>
<% end -%>