Ghost/core/frontend/meta/generate-excerpt.js
Hannah Wolfe 84c2154cbe
Fixed missing renames getExcerpt -> generateExcerpt
refs: fbf0636936

- I renamed this pattern in a bunch of places, but missed a few, leaving the code messy and confusing
- This makes the naming consistent
2021-07-02 09:44:18 +01:00

24 lines
780 B
JavaScript

const downsize = require('downsize');
function generateExcerpt(html, truncateOptions) {
truncateOptions = truncateOptions || {};
// Strip inline and bottom footnotes
let excerpt = html.replace(/<a href="#fn.*?rel="footnote">.*?<\/a>/gi, '');
excerpt = excerpt.replace(/<div class="footnotes"><ol>.*?<\/ol><\/div>/, '');
// Make sure to have space between paragraphs and new lines
excerpt = excerpt.replace(/(<\/p>|<br>)/gi, ' ');
// Strip other html
excerpt = excerpt.replace(/<\/?[^>]+>/gi, '');
excerpt = excerpt.replace(/(\r\n|\n|\r)+/gm, ' ');
if (!truncateOptions.words && !truncateOptions.characters) {
truncateOptions.words = 50;
}
return downsize(excerpt, truncateOptions);
}
module.exports = generateExcerpt;