eleventy-plugin-excerpt
v1.1.2
Published
Eleventy plugin for extracting template excerpts
Downloads
2,502
Maintainers
Readme
eleventy-plugin-excerpt
Eleventy plugin for extracting template excerpts
Install
npm install eleventy-plugin-excerpt
Add it to your .eleventy.js
const excerpt = require('eleventy-plugin-excerpt');
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(excerpt);
};
Usage
This plugin adds a universal shortcode named excerpt
which takes one argument: a template object.
By default, the excerpt will be the first paragraph of the template content.
Liquid
{%- for post in collections.post -%}
{% excerpt post %}
{%- endfor -%}
Nunjucks
{%- for post in collections.post -%}
{% excerpt post %}
{%- endfor -%}
Handlebars
{{#each collections.post}}
{{{ excerpt this }}}
{{/each}}
JavaScript function
module.exports = function({ collections }) {
return collections.post.map(post => {
return `<div>${this.excerpt(post)}</div>`;
});
};
Options
excerptSeparator
Everything in the rendered template content up to and including this string becomes the excerpt.
Optional, defaults to '</p>'
.
For example, if you configure the plugin like this
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(excerpt, {
excerptSeparator: '<!--more-->'
});
};
Then you can have multi paragraph excerpts
---
# ...
---
In the excerpt
Also in the excerpt
<!--more-->
Not in the excerpt
Override excerpt
If your template's front-matter or data file contains a property called "excerpt", that string will be used instead of extracting the excerpt from the template content.
---
excerpt: 'This is the excerpt'
---
Not the excerpt
License
MIT