Correctly parse names out of itemprop/author segments

If these nodes are setup correctly with structured data, parse
out the name instead of taking the entire textContent.
This commit is contained in:
Jackson Harper 2022-11-25 10:19:58 +08:00
parent eb920eeae8
commit cc77e72a5b

View file

@ -1089,9 +1089,14 @@ Readability.prototype = {
var itemprop = node.getAttribute("itemprop");
}
if ((rel === "author" || (itemprop && itemprop.indexOf("author") !== -1) || this.REGEXPS.byline.test(matchString)) && this._isValidByline(node.textContent)) {
this._articleByline = node.textContent.trim();
return true;
if ((rel === "author" || itemprop && itemprop.indexOf("author") !== -1) || this.REGEXPS.byline.test(matchString)) {
var allText = node.textContent.trim()
var nameText = node.querySelector('span[itemprop="name"]')?.textContent
const bylineText = nameText ?? allText
if (this._isValidByline(bylineText)) {
this._articleByline = bylineText
return true;
}
}
return false;