Skip to content

Commit

Permalink
Handle article:author meta tag. Fixes #938 (#942)
Browse files Browse the repository at this point in the history
* Handle article:author meta tag. Fixes #938

* Add newly found BBC byline, revert apparently unnecessarily regex change.

---------

Co-authored-by: Gijs Kruitbosch <[email protected]>
  • Loading branch information
danielnixon and gijsk authored Jan 2, 2025
1 parent d9c588a commit b6ff1b6
Show file tree
Hide file tree
Showing 5 changed files with 2,538 additions and 2 deletions.
23 changes: 22 additions & 1 deletion Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,20 @@ Readability.prototype = {
}
},

/**
* Tests whether a string is a URL or not.
*
* @param {string} str The string to test
* @return {boolean} true if str is a URL, false if not
*/
_isUrl(str) {
try {
new URL(str);
return true;
} catch {
return false;
}
},
/**
* Converts each <a> and <img> uri in the given element to an absolute URI,
* ignoring #ref URIs.
Expand Down Expand Up @@ -1771,13 +1785,20 @@ Readability.prototype = {
metadata.title = this._getArticleTitle();
}

const articleAuthor =
typeof values["article:author"] === "string" &&
!this._isUrl(values["article:author"])
? values["article:author"]
: undefined;

// get author
metadata.byline =
jsonld.byline ||
values["dc:creator"] ||
values["dcterm:creator"] ||
values.author ||
values["parsely-author"];
values["parsely-author"] ||
articleAuthor;

// get description
metadata.excerpt =
Expand Down
10 changes: 10 additions & 0 deletions test/test-pages/article-author-tag/expected-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "If You Can Picture A Tarot Card, It's Because of These 3 People",
"byline": "Laura June Topolsky",
"dir": null,
"lang": "en",
"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...",
"siteName": "Atlas Obscura",
"publishedTime": "2015-07-10 09:53:00 -0400",
"readerable": true
}
Loading

0 comments on commit b6ff1b6

Please sign in to comment.