Skip to content

Commit

Permalink
Performance: Allow passing the dom directly
Browse files Browse the repository at this point in the history
This allows customizing the parser (using htmlparser2 instead of default's more strict and slower parse5). Also, if you do any post-processing, you can reuse the object and avoid parsing twice (expensive)
  • Loading branch information
masylum authored Jun 23, 2024
1 parent d641cbd commit 5d5136f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/metascraper/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = rules => {
return async ({
url,
html = '',
dom,
rules: inlineRules,
validateUrl = true,
...props
Expand All @@ -24,10 +25,11 @@ module.exports = rules => {
code: 'INVALID_URL'
})
}
const htmlDom = dom || load(html, { baseURI: url })

return getData({
url,
htmlDom: load(html, { baseURI: url }),
htmlDom,
rules: mergeRules(inlineRules, loadedRules),
...props
})
Expand Down

0 comments on commit 5d5136f

Please sign in to comment.