🐛 Fixed custom excerpts sometimes being cut off (#19560)

refs TryGhost/Ghost#19559
- custom excerpts are truncated based on character length
- escaped characters added extra length but we didn't account for this,
resulting in poor truncation of excerpts
This commit is contained in:
Steve Larson 2024-01-23 14:45:27 -06:00 committed by GitHub
parent b15534690c
commit 40891272dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,7 +22,7 @@ module.exports = function excerpt(options) {
} else { } else {
excerptText = ''; excerptText = '';
} }
excerptText = _.escape(excerptText); excerptText = _.escape(excerptText);
truncateOptions = _.reduce(truncateOptions, (_truncateOptions, value, key) => { truncateOptions = _.reduce(truncateOptions, (_truncateOptions, value, key) => {
@ -32,8 +32,9 @@ module.exports = function excerpt(options) {
return _truncateOptions; return _truncateOptions;
}, {}); }, {});
// For custom excerpts, make sure we truncate them only based on length
if (!_.isEmpty(this.custom_excerpt)) { if (!_.isEmpty(this.custom_excerpt)) {
truncateOptions.characters = this.custom_excerpt.length; truncateOptions.characters = excerptText.length; // length is expanded by use of escaped characters
if (truncateOptions.words) { if (truncateOptions.words) {
delete truncateOptions.words; delete truncateOptions.words;
} }