---
title: "Reading time"
slug: reading-time
section: tech
date: 2015-06-05T12:39:00.000Z
canonical: https://roland.leth.ro/blog/tech/reading-time
---

I always wanted to add this to my posts, but never really got to do it. [As](/tech/blog/dropbox-sync-for-the-blog) [usual](/tech/blog/stop-thinking-its-too-hard), 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`:

```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 -%>
```