0.2.1 • Published 2 years ago

eleventy-plugin-wordcount-extended v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

eleventy-plugin-wordcount-extended

An Eleventy universal plugin to An eleventy plugin to count and output the number of words in a string.

Nunjuck's buildin filter wordcount does not correctly calculate the word count of non-ASCII strings, for example, the following code generates 1 1, the third line is ignored by nunjuck.

{{ "Eleventy" | wordcount }}
{{ "Eleventy, 一个更简单的静态站点生成器" | wordcount }}
{{ "😀😁😂😃😄😅😆😇😈" | wordcount }}

With this version of wordcount, the result would be 1 14 9.

Installation

Available on npm.

npm install eleventy-plugin-wordcount-extended --save

Open up your Eleventy config file (probably .eleventy.js) and add the plugin:

const wordcountPlugin = require("eleventy-plugin-wordcount-extended");
module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(wordcountPlugin);
};

Usage

In your (Nunjucks, Liquid or Handlebars) templates, use the following syntax to get the word count of a string:

// nunjucks/liquid 
{{ content | wordcount }} 
// handlebars 
{{{ wordcount content }}}

Note that the wordcount filter from this plugin will override that of nunjuck, if this is not what you want, you can fork the repository, edit the entry point file, and replace wordcount with other names:

module.exports = function (eleventyConfig) {
  eleventyConfig.addFilter("wc", wordcount);
};

Then apply it to the templates:

{{ content | wc }}
0.2.1

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

1.0.0

2 years ago