Skip to content

Commit

Permalink
Add support for author array in JSON-LD. mozilla#617 (mozilla#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyjeain authored Aug 21, 2020
1 parent 3844d8f commit 3fe8281
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,8 +1380,19 @@ Readability.prototype = {
} else if (typeof parsed.headline === "string") {
metadata.title = parsed.headline.trim();
}
if (parsed.author && typeof parsed.author.name === "string") {
metadata.byline = parsed.author.name.trim();
if (parsed.author) {
if (typeof parsed.author.name === "string") {
metadata.byline = parsed.author.name.trim();
} else if (Array.isArray(parsed.author) && parsed.author[0] && typeof parsed.author[0].name === "string") {
metadata.byline = parsed.author
.filter(function(author) {
return author && typeof author.name === "string";
})
.map(function(author) {
return author.name.trim();
})
.join(", ");
}
}
if (typeof parsed.description === "string") {
metadata.excerpt = parsed.description.trim();
Expand Down
2 changes: 1 addition & 1 deletion test/test-pages/aclu/expected-metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Facebook Is Tracking Me Even Though I’m Not on Facebook",
"byline": "By Daniel Kahn Gillmor, Senior Staff Technologist, ACLU Speech, Privacy, and Technology Project",
"byline": "Daniel Kahn Gillmor",
"dir": "ltr",
"excerpt": "Facebook collects data about people who have never even opted in. But there are ways these non-users can protect themselves.",
"siteName": "American Civil Liberties Union",
Expand Down
2 changes: 1 addition & 1 deletion test/test-pages/folha/expected-metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Tite diz que errou ao levar taça da Libertadores a Lula em 2012",
"byline": "21.dez.2018 às 10h55",
"byline": "Bruno (Henrique Zecchin) Rodrigues",
"dir": null,
"excerpt": "Na ocasião, técnico do Corinthians entregou réplica do troféu ao ex-presidente",
"siteName": "Folha de S.Paulo",
Expand Down
2 changes: 1 addition & 1 deletion test/test-pages/videos-2/expected-metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Screenshot : «Vape Wave», «6 Days», «Alphonse Président»…",
"byline": "Par Alexandre Hervaud et Jérémy Piette",
"byline": "Alexandre Hervaud, Jérémy Piette",
"dir": null,
"excerpt": "Séries, documentaires, programmes jeunesse… Retrouvez les recommandations de Libération pour savoir quoi regarder sur vos écrans cette semaine.\nPour dépasser...",
"siteName": "Libération",
Expand Down

0 comments on commit 3fe8281

Please sign in to comment.