Skip to content

Commit

Permalink
Merge pull request #413 from extractus/8.0.16
Browse files Browse the repository at this point in the history
v8.0.16
  • Loading branch information
ndaidong authored Nov 9, 2024
2 parents e15b3af + bc631c5 commit 197a2b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "8.0.15",
"version": "8.0.16",
"name": "@extractus/article-extractor",
"description": "To extract main article from given URL",
"homepage": "https://github.com/extractus/article-extractor",
Expand Down Expand Up @@ -38,8 +38,8 @@
},
"devDependencies": {
"@types/sanitize-html": "^2.13.0",
"eslint": "^9.13.0",
"globals": "^15.11.0",
"eslint": "^9.14.0",
"globals": "^15.12.0",
"https-proxy-agent": "^7.0.5",
"nock": "^13.5.5"
},
Expand Down
12 changes: 8 additions & 4 deletions src/utils/extractLdSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const parseJson = (text) => {
}
}

const isAllowedLdJsonType = (ldJson) => {
const rootLdJsonType = ldJson['@type'] || ''
const arr = isArray(rootLdJsonType) ? rootLdJsonType : [rootLdJsonType]
const ldJsonTypes = arr.filter(x => !!x)
return ldJsonTypes.length > 0 && ldJsonTypes.some(x => typeSchemas.includes(x.toLowerCase()))
}

/**
* Parses JSON-LD data from a document and populates an entry object.
* Only populates if the original entry object is empty or undefined.
Expand All @@ -59,10 +66,7 @@ export default (document, entry) => {
const ldSchemas = document.querySelectorAll('script[type="application/ld+json"]')
ldSchemas.forEach(ldSchema => {
const ldJson = parseJson(ldSchema.textContent.replace(/[\n\r\t]/g, ''))
const ldJsonType = ldJson['@type']?.toLowerCase() || null
const isAllowedLdJsonType = ldJsonType ? typeSchemas.includes(ldJsonType) : false

if (ldJson && isAllowedLdJsonType) {
if (ldJson && isAllowedLdJsonType(ldJson)) {
Object.entries(attributeLists).forEach(([key, attr]) => {
if (!entry[key] || !ldJson[attr]) {
return
Expand Down

0 comments on commit 197a2b5

Please sign in to comment.