mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-16 20:43:01 +03:00
d7b9eb6176
refs #6534 - this is an initial fix for having no description at all unless a meta description is provided - we may need to tweak the lengths / provide different lengths for different values in future
21 lines
677 B
JavaScript
21 lines
677 B
JavaScript
var downsize = require('downsize');
|
|
|
|
function getExcerpt(html, truncateOptions) {
|
|
truncateOptions = truncateOptions || {};
|
|
// Strip inline and bottom footnotes
|
|
var excerpt = html.replace(/<a href="#fn.*?rel="footnote">.*?<\/a>/gi, '');
|
|
excerpt = excerpt.replace(/<div class="footnotes"><ol>.*?<\/ol><\/div>/, '');
|
|
// Strip other html
|
|
excerpt = excerpt.replace(/<\/?[^>]+>/gi, '');
|
|
excerpt = excerpt.replace(/(\r\n|\n|\r)+/gm, ' ');
|
|
/*jslint regexp:false */
|
|
|
|
if (!truncateOptions.words && !truncateOptions.characters) {
|
|
truncateOptions.words = 50;
|
|
}
|
|
|
|
return downsize(excerpt, truncateOptions);
|
|
}
|
|
|
|
module.exports = getExcerpt;
|