From cc77e72a5b492f25e59f6a7ffc5d9521380f9260 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 25 Nov 2022 10:19:58 +0800 Subject: [PATCH] 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. --- packages/readabilityjs/Readability.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index 7f787bbb5..1df750d69 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -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;