Add a Plugin

Install

npm install --save eleventy-plugin-reading-time

Usage

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