-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #375 from extractus/dev
v8.0.8
- Loading branch information
Showing
16 changed files
with
226 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ | |
}, | ||
"dependencies": { | ||
"express": "^4.18.2", | ||
"got": "^13.0.0" | ||
"got": "^14.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const typeSchemas = [ | ||
'aboutpage', | ||
'checkoutpage', | ||
'collectionpage', | ||
'contactpage', | ||
'faqpage', | ||
'itempage', | ||
'medicalwebpage', | ||
'profilepage', | ||
'qapage', | ||
'realestatelisting', | ||
'searchresultspage', | ||
'webpage', | ||
'website', | ||
'article', | ||
'advertisercontentarticle', | ||
'newsarticle', | ||
'analysisnewsarticle', | ||
'askpublicnewsarticle', | ||
'backgroundnewsarticle', | ||
'opinionnewsarticle', | ||
'reportagenewsarticle', | ||
'reviewnewsarticle', | ||
'report', | ||
'satiricalarticle', | ||
'scholarlyarticle', | ||
'medicalscholarlyarticle', | ||
] | ||
|
||
const attributeLists = { | ||
description: 'description', | ||
image: 'image', | ||
author: 'author', | ||
published: 'datePublished', | ||
type: '@type', | ||
} | ||
|
||
/** | ||
* Parses JSON-LD data from a document and populates an entry object. | ||
* Only populates if the original entry object is empty or undefined. | ||
* | ||
* @param {Document} document - The HTML Document | ||
* @param {Object} entry - The entry object to merge/populate with JSON-LD. | ||
* @returns {Object} The entry object after being merged/populated with data. | ||
*/ | ||
export default (document, entry) => { | ||
const ldSchema = document.querySelector('script[type="application/ld+json"]')?.textContent | ||
|
||
if (!ldSchema) { | ||
return entry | ||
} | ||
|
||
const ldJson = JSON.parse(ldSchema) | ||
Object.entries(attributeLists).forEach(([key, attr]) => { | ||
if ((typeof entry[key] === 'undefined' || entry[key] === '') && ldJson[attr]) { | ||
if (key === 'type' && typeof ldJson[attr] === 'string') { | ||
return entry[key] = typeSchemas.includes(ldJson[attr].toLowerCase()) ? ldJson[attr].toLowerCase() : '' | ||
} | ||
|
||
if (typeof ldJson[attr] === 'string') { | ||
return entry[key] = ldJson[attr].toLowerCase() | ||
} | ||
|
||
if (Array.isArray(ldJson[attr]) && typeof ldJson[attr][0] === 'string') { | ||
return entry[key] = ldJson[attr][0].toLowerCase() | ||
} | ||
} | ||
}) | ||
|
||
return entry | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.