A non-dependency reading time plugin for Eleventy static site generator. This plugin provides a template tag which prints the number of minutes or seconds required to read the given text.
npm install --save eleventy-plugin-reading-time
In your Eleventy config file (defaults to .eleventy.js
):
const readingTime = require('eleventy-plugin-reading-time');
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(readingTime);
};
Now you can use the readingTime
filter in your Nunjuck templates:
<span>About {{ someTextContent | readingTime } reading time}</span>
prints
<span>About 6 min reading time</span>
Example post.njk
template:
<article role="article">
<header>
<h1>{{ title }}</h1>
<p>
<span class="meta__stats">About {{ content | readingTime }} reading time</span>
</p>
</header>
<div>
{{ content | safe }}
</div>
</article>
If you're in a collection loop, this filter accepts a collection object too:
{% for post in posts %}
<li>
<h1>{{post.title}}</h1>
<p>About {{ post | readingTime }} reading time.</p>
</li>
{% endfor %}
- Support more template engines.
MIT.