Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/johanbrook/eleventy-plugin-reading-time

A non-dependency reading time plugin for Eleventy static site generator.
https://github.com/johanbrook/eleventy-plugin-reading-time

Last synced: 3 months ago
JSON representation

A non-dependency reading time plugin for Eleventy static site generator.

Awesome Lists containing this project

README

        

# Reading time plugin for Eleventy

A non-dependency reading time plugin for [Eleventy](https://www.11ty.io/) static site generator. This plugin provides a template tag which prints the number of minutes or seconds required to read the given text.

## Install

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

## Usage

In your Eleventy config file (defaults to `.eleventy.js`):

```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:

```html
About {{ someTextContent | readingTime } reading time}
```

prints

```html
About 6 min reading time
```

Example `post.njk` template:

```html


{{ title }}



About {{ content | readingTime }} reading time



{{ content | safe }}

```

If you're in a collection loop, this filter accepts a collection object too:

```html
{% for post in posts %}


  • {{post.title}}


    About {{ post | readingTime }} reading time.



  • {% endfor %}
    ```

    ## To Do

    - [ ] Support more template engines.

    ## License

    MIT.