metalsmith / excerpts

A Metalsmith plugin to extract an excerpt from HTML files.
MIT License
24 stars 26 forks source link

Add option to strip surrounding paragraph element #8

Closed jkarsrud closed 3 years ago

jkarsrud commented 10 years ago

Sometimes it's a use-case to want to present the excerpt in a different way than the rest of the content — for instance with a different class name on that element without having to wrap it in a different element.

I'd be happy to do a PR on this if you think it's a good idea?

maiertech commented 8 years ago

I think the excerpt variable that the plugin creates should be an object and return excerpt.text, excerpt.html (with <p></p> stripped but all other HTML preserved). I tend to need a text version for the description meta tag and the HTML version for overview or archive pages.

MorganConrad commented 7 years ago

Returning an object might help, but this is a good use case for metalsmith-keymaster. (hope it's o.k. to plug my own plugin). e.g.

.use(excerpts())
.use(keymaster({  // remove trailing </p> from excerpt and replace with ...
      from: function(fileData) {
         var ex = fileData.excerpt || "";
         return ex.substring(0, ex.length - 4) + " ...";
      },
      to: "excerpt"
   }))
SmashManiac commented 6 years ago

Such a feature would be great for Atom feed summaries.

woodyrew commented 6 years ago

PR would be welcome.

woodyrew commented 3 years ago

This can be done with #32