eleventy-plugin-reading-time

Add the reading time for a text as template tag.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
eleventy-plugin-reading-time
2260.0.14 years ago4 years agoMinified + gzip package size for eleventy-plugin-reading-time in KB

Readme

Reading time plugin for Eleventy
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.

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

To Do

  • Support more template engines.

License

MIT.