Skip to content

Commit

Permalink
Rename interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 26, 2018
1 parent 88ec8e7 commit df7e07f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -28,7 +28,7 @@ const getLinks = require('html-links')
const {body: html} = await got(url)
const links = getLinks({html, url})

console.log(links)
links.forEach(({ url, normalizeUrl }, index) => console.log(normalizeUrl))

// => [
// 'https://microlink.io/component---src-layouts-index-js-86b5f94dfa48cb04ae41.js',
Expand Down
48 changes: 24 additions & 24 deletions __snapshots__/index.js.snap-shot
@@ -1,72 +1,72 @@
exports['get links from a semantic markup 1'] = [
{
"normalized": "https://google.com",
"origin": "https://google.com"
"normalizeUrl": "https://google.com",
"url": "https://google.com"
},
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

exports['remove duplicate links 1'] = [
{
"normalized": "https://google.com",
"origin": "https://google.com"
"normalizeUrl": "https://google.com",
"url": "https://google.com"
},
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

exports['final slash doesnt matter 1'] = [
{
"normalized": "https://google.com",
"origin": "https://google.com/"
"normalizeUrl": "https://google.com",
"url": "https://google.com/"
},
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

exports['query string parameters position are not relevant 1'] = [
{
"normalized": "https://google.com/?foo=bar&hello=world",
"origin": "https://google.com?hello=world&foo=bar"
"normalizeUrl": "https://google.com/?foo=bar&hello=world",
"url": "https://google.com?hello=world&foo=bar"
},
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

exports['tag `link` support 1'] = [
{
"normalized": "https://microlink.io/default.css",
"origin": "default.css"
"normalizeUrl": "https://microlink.io/default.css",
"url": "default.css"
}
]

exports['resolve relative links 1'] = [
{
"normalized": "https://microlink.io/login",
"origin": "/login"
"normalizeUrl": "https://microlink.io/login",
"url": "/login"
}
]

exports['string support 1'] = [
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

exports['regex support 1'] = [
{
"normalized": "https://facebook.com",
"origin": "https://facebook.com"
"normalizeUrl": "https://facebook.com",
"url": "https://facebook.com"
}
]

8 changes: 4 additions & 4 deletions src/index.js
Expand Up @@ -15,8 +15,8 @@ const getLink = ({ url, el, attribute }) => {
const attr = get(el, `attribs.${attribute}`, '')
if (isEmpty(attr)) return null
return Object.assign({
normalized: getUrl(url, attr),
origin: attr
normalizeUrl: getUrl(url, attr),
url: attr
})
}

Expand Down Expand Up @@ -57,12 +57,12 @@ const addLinksByAttribute = ({ $, tags, attribute, url, blackListPattern }) => {

const isAlreadyAdded = includes(
acc,
item => getUrl(item.normalized) === link.normalized
item => getUrl(item.normalizeUrl) === link.normalizeUrl
)
if (isAlreadyAdded) return acc

const isBlacklist = includes(blackListPattern, pattern =>
pattern.test(link.normalized)
pattern.test(link.normalizeUrl)
)
if (!isBlacklist) acc.push(link)

Expand Down

0 comments on commit df7e07f

Please sign in to comment.