mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
fix: update title generator to include the punctuation, and also take into account question marks and exclamation marks
This commit is contained in:
@@ -264,12 +264,21 @@ Helpers.generateTitle = (html) => {
|
||||
title = $('h1, h2, h3, h4, h5, h6, title, p, span').first().text();
|
||||
|
||||
// Fall back to newline splitting (i.e. if no paragraph elements)
|
||||
title = title || html.split('\n').filter(Boolean)[0];
|
||||
title = title || html.split('\n').filter(Boolean).shift();
|
||||
|
||||
// Split sentences and use only first one
|
||||
const split = title.split('. ');
|
||||
if (split.length > 1) {
|
||||
title = split.shift();
|
||||
const sentences = title
|
||||
.split(/(\.|\?|!)\s/)
|
||||
.reduce((memo, cur, idx, sentences) => {
|
||||
if (idx % 2) {
|
||||
memo.push(`${sentences[idx - 1]}${cur}`);
|
||||
}
|
||||
|
||||
return memo;
|
||||
}, []);
|
||||
|
||||
if (sentences.length > 1) {
|
||||
title = sentences.shift();
|
||||
}
|
||||
|
||||
// Truncate down if too long
|
||||
|
||||
Reference in New Issue
Block a user