mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
84c2154cbe
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
24 lines
780 B
JavaScript
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;
|