eleventy-plugin-excerpt

1.1.2 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.2610latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.2610
1.1.10
1.1.00
1.0.00

Package Sidebar

Install

npm i eleventy-plugin-excerpt

Weekly Downloads

610

Version

1.1.2

License

MIT

Unpacked Size

6.45 kB

Total Files

7

Last publish

Collaborators

  • psalaets