A lightweight wrapper for making available reading-time to the Eleventy Static Site Generator.
npm i @photogabble/eleventy-plugin-word-stats
In your Eleventy config file (defaults to .eleventy.js):
const wordStats = require('@photogabble/eleventy-plugin-word-stats');
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(wordStats);
};
Now the wordStats
filter will be available to use in your templates. For example with Nunjuck it can be used as such:
<p>{{ content | wordStats }}</p>
Which will by default output along the lines of:
<p>1244 words, 6 min read</p>
interface Options {
output?: (stats: object) => string;
wordBound?: (char: string) => boolean;
wordsPerMinute?: number;
}
Function that controls the output of the wordStats
filter. It's stats argument is provided an object that matches the following interface:
interface ReadTimeResults {
text: string;
time: number;
words: number;
minutes: number;
}
If all you need is the word count formatted, there are two very good alternatives to this plugin:
This 11ty plugin is open-sourced software licensed under the MIT License