A simple time to read extension for RainLab Blog plugin.
Blog Time to Read adds a basic time to read calculation for your awesome posts.
The Blog Time to Read plugin requires RainLab Blog and RainLab Translate.
Plugin defaults are controlled via backend settings panel, just look for Blog Time to Read in your Settings dashboard. Currently you can set default reading speed (words per minute, the initial value is 300 wpm) and result rounding to the closest higher integer (it is enabled by default).
The Blog Time to Read plugin provides several ways to get time to read for your blog post:
-
The default
Post
model is extended withtimeToRead
property which gives you a number in minutes to read the post. The default settings are being used for calculation.{{ post.timeToRead }}
-
Templates can use a new Twig
timeToRead
filter which uses the initial settings by default but also allows to override them explicitly (the example shows how you can set 100 wpm speed without rounding for a filter).{{ post.content | timeToRead(100, false) }}
-
TimeToRead component is available for use.
Component properties:
- Post slug - get time to read for the post specified by the slug value from URL parameter;
- Default reading speed - words per minute by default;
- Rounding up - round fractional values to the next highest integer value.
Please note that default component partial contains the call to translation filter.
<div>
<p>{{ ":count min to read" |_({ count: __SELF__.minutes }) }}</p>
</div>
It allows you to edit the message using the Translate plugin and specify messages for different languages too.