mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Handle multiple ldjson instances on a page
This commit is contained in:
parent
05013dcba7
commit
ce40b98969
1 changed files with 5 additions and 1 deletions
|
|
@ -4,7 +4,11 @@
|
|||
|
||||
// LD+JSON extraction
|
||||
((ib) => {
|
||||
ld = document.querySelector('script[type="application/ld+json"]').innerText
|
||||
ld = Array.from(document.querySelectorAll('script[type="application/ld+json"]'))
|
||||
.map(e => e.innerText)
|
||||
.sort((a,b) => a.length - b.length)
|
||||
.pop();
|
||||
if (!ld) alert("No recipe data found on this page. Sorry!");
|
||||
ld = JSON.parse(ld);
|
||||
if (ld["@type"] != "Recipe"){ ld=(ld["@graph"]??ld).find((item)=>item["@type"]=="Recipe") }
|
||||
delete ld.review;
|
||||
|
|
|
|||
Loading…
Reference in a new issue