Fall back to the original title if after trimming the text we have too many words before the colon.

pull/411/head
Andres Rey 7 years ago committed by Gijs
parent c2e370c2c7
commit 9ce4d87232

@ -375,8 +375,13 @@ Readability.prototype = {
curTitle = origTitle.substring(origTitle.lastIndexOf(':') + 1);
// If the title is now too short, try the first colon instead:
if (wordCount(curTitle) < 3)
if (wordCount(curTitle) < 3) {
curTitle = origTitle.substring(origTitle.indexOf(':') + 1);
// But if we have too many words before the colon there's something weird
// with the titles and the H tags so let's just use the original title instead
} else if (wordCount(origTitle.substr(0, origTitle.indexOf(':'))) > 5) {
curTitle = origTitle;
}
}
} else if (curTitle.length > 150 || curTitle.length < 15) {
var hOnes = doc.getElementsByTagName('h1');

Loading…
Cancel
Save