@myxotod/eleventy-plugin-readingtime

2.0.0 • Public • Published

eleventy-plugin-readingtime

A lightweight eleventy plugin to display page/post reading time in minutes. No dependencies.

NPM Version NPM Downloads npm bundle size (scoped version)

Usage

Install this package

npm i @myxotod/eleventy-plugin-readingtime

Add and register it inside your .eleventy.js config file

// .eleventy.js
const readingtime = require("@myxotod/eleventy-plugin-readingtime");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(readingtime);
};

Finally use it in your code with the readingtime-filter

<div>Reading time: {{ post | readingtime }}</div>

Example output

<div>Reading time: ~3min</div>

You will have to pass the whole post or page to the filter as shown above.

Options

You can pass several options when adding the plugin in your eleventy config file like so:

eleventyConfig.addPlugin(readingtime, {
  wordsPerMinute: 200,
  suffixDisplay: true,
  suffixText: 'min',
  prefixDisplay: true,
  prefixText: '~',
  verbose: false
});
Option Default Description
wordsPerMinute 200 Average number of words read per minute (higher values result in faster reading times)
suffixDisplay true Show or hide the suffix
suffixText 'min' The suffix to be shown
prefixDisplay true Show or hide the prefix
prefixText '~' The prefix to be shown
verbose false Output additional data to your terminal when an eleventy build happens

License

MIT @ Maximilian Boll

Package Sidebar

Install

npm i @myxotod/eleventy-plugin-readingtime

Weekly Downloads

15

Version

2.0.0

License

MIT

Unpacked Size

13.4 kB

Total Files

7

Last publish

Collaborators

  • myxotod