Adding read time to posts made easy

Last updated: Aug 08, 2020 1 minute read

While building this new Website/Blog i used some Tailwind UI components in order to make it somewhat good looking. One of these components was a card for Blog posts (who would have thought :D).

In the examples there was a "read time" displayed on the cards. I've never thought about that "feature", but it made total sense to me and I realized most Blogs and such I visit have this today.

I thought about a simple "calculation", count the words in the post and divide it by an average word read count per minute. Pretty simple actually.

While I quickly researched the average word count, I stumbled upon a nice little PHP package called "read-time". It can be used within any PHP Application (but requires PHP >= 7.0), but also has an integration for Laravel:

You can simply give it a text, it will count the words, takes 300 words per minute by default for its calculation and outputs "6 min read" for example. It also comes with Translations, RTL support and some more little features.

Since I display a list of topics I wrote about, i thought it would also be nice to display the total read count on the topic in its card. And again, this package jumped in, because you can simply pass an array of texts to it and it will calculate the accumulated read time.

I hope this might also come in handy for you!