Skip to content

Commit b6ff1b6

Browse files
danielnixongijsk
andauthored
Handle article:author meta tag. Fixes #938 (#942)
* Handle article:author meta tag. Fixes #938 * Add newly found BBC byline, revert apparently unnecessarily regex change. --------- Co-authored-by: Gijs Kruitbosch <[email protected]>
1 parent d9c588a commit b6ff1b6

File tree

5 files changed

+2538
-2
lines changed

5 files changed

+2538
-2
lines changed

Readability.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,20 @@ Readability.prototype = {
432432
}
433433
},
434434

435+
/**
436+
* Tests whether a string is a URL or not.
437+
*
438+
* @param {string} str The string to test
439+
* @return {boolean} true if str is a URL, false if not
440+
*/
441+
_isUrl(str) {
442+
try {
443+
new URL(str);
444+
return true;
445+
} catch {
446+
return false;
447+
}
448+
},
435449
/**
436450
* Converts each <a> and <img> uri in the given element to an absolute URI,
437451
* ignoring #ref URIs.
@@ -1771,13 +1785,20 @@ Readability.prototype = {
17711785
metadata.title = this._getArticleTitle();
17721786
}
17731787

1788+
const articleAuthor =
1789+
typeof values["article:author"] === "string" &&
1790+
!this._isUrl(values["article:author"])
1791+
? values["article:author"]
1792+
: undefined;
1793+
17741794
// get author
17751795
metadata.byline =
17761796
jsonld.byline ||
17771797
values["dc:creator"] ||
17781798
values["dcterm:creator"] ||
17791799
values.author ||
1780-
values["parsely-author"];
1800+
values["parsely-author"] ||
1801+
articleAuthor;
17811802

17821803
// get description
17831804
metadata.excerpt =
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"title": "If You Can Picture A Tarot Card, It's Because of These 3 People",
3+
"byline": "Laura June Topolsky",
4+
"dir": null,
5+
"lang": "en",
6+
"excerpt": "Picture a deck of tarot cards. What do you see? Maybe the Magician in his rich red robes, right arm raised high above him. Or the skeleton on horseback for...",
7+
"siteName": "Atlas Obscura",
8+
"publishedTime": "2015-07-10 09:53:00 -0400",
9+
"readerable": true
10+
}

0 commit comments

Comments
 (0)