Skip to content

Commit

Permalink
Expose tags and cheerio opts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 21, 2018
1 parent cf1af6f commit 9c27283
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { getUrl } = require('@metascraper/helpers')
const cheerio = require('cheerio')
const matcher = require('matcher')

const LINKS_ATTRIBUTES = {
const TAGS = {
background: ['body'],
cite: ['blockquote', 'del', 'ins', 'q'],
data: ['object'],
Expand Down Expand Up @@ -67,11 +67,16 @@ const getLinksByAttribute = ({ selector, attribute, url, whitelist }) => {
)
}

module.exports = ({ html = '', url = '', whitelist = false } = {}) => {
const $ = cheerio.load(html)
module.exports = ({
html = '',
url = '',
whitelist = false,
cheerioOpts = {}
} = {}) => {
const $ = cheerio.load(html, cheerioOpts)

return reduce(
LINKS_ATTRIBUTES,
TAGS,
(acc, htmlTags, attribute) => {
const links = getLinksByAttribute({
selector: $(htmlTags.join(',')),
Expand All @@ -84,3 +89,5 @@ module.exports = ({ html = '', url = '', whitelist = false } = {}) => {
[]
)
}

module.exports.TAGS = TAGS

0 comments on commit 9c27283

Please sign in to comment.