Skip to content

Generate excerpt when no excerpt_separator present in content #2890

@keithjgrant

Description

@keithjgrant

Is your feature request related to a problem? Please describe.

I'm trying to use excerpts to generate my site's meta description tags, but the current implementation only generates an excerpt when the separator is present in my markdown. It's null/undefined otherwise.

Some of my posts use the <!-- excerpt --> separator, but most do not, and I expect I will forget to add it many times in the future.

Describe the solution you'd like

I'd love for a way to generate excerpts for all pages, even when the separator isn't present. This could be done via character limit, word limit, or paragraph count — any of these would be better than the current behavior, IMO.

I'd like to be able to do something like this to configure it:

eleventyConfig.setFrontMatterParsingOptions({
  excerpt: true,
  excerpt_alias: '<!-- excerpt -->',
  excerpt_char_limit: 180,         // specify a truncation option to use if the excert_alias is missing
});

It might make sense to leave the current behavior as is, unless this new option is specified.

Describe alternatives you've considered

There's clearly a need here, as I found several blog posts — however most of these solutions were tailored towards collections, not individual pages, and it's taking some work for me to adapt their approaches:

I'm currently using {{ content | striptags() | truncate(160) }} in my include'd template partial, but this uses the final rendered HTML, so it has extra content such as the post date and title that I render before the main body of my page. I'd like to keep that stuff out of my summary.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions