Skip to content

Commit

Permalink
Gracefully handle malformed JSONLD
Browse files Browse the repository at this point in the history
  • Loading branch information
jmduke committed Sep 10, 2024
1 parent 8e6d7ef commit 845b75b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/parsers/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ const JSONLD_RULE = (html: string) => {
identifier: "jsonld",
metadata: { value: text },
},
...(JSON.parse(text)
...((() => {
try {
return JSON.parse(text)
} catch (error) {
console.error("Error parsing JSON-LD:", error);
return {};
}
})()
["@graph"]?.filter((i: { sameAs: string[] }) => i.sameAs)
.flatMap((i: any) => {
return i.sameAs.flatMap((url: string) => {
Expand Down

0 comments on commit 845b75b

Please sign in to comment.