Skip to content

Commit

Permalink
Allow using regex paths in blacklist config option
Browse files Browse the repository at this point in the history
  • Loading branch information
juljimm committed Dec 5, 2020
1 parent b96be2c commit 74a342f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ async function start(options) {
const isUnique = url => !urls.find(oldUrl => short(url) === short(oldUrl))

/** @param {Url} url */
const isntBlacklisted = url => !options.blacklist.includes(url.path)
const isntBlacklisted = url =>
!options.blacklist.some(e => {
if (typeof e == "string") {
return e == url.path;
} else if (e instanceof RegExp) {
return e.test(url.path);
} else {
console.warn("config option 'blacklist' should contain only strings and/or regular expressions");
return true; // Ignore non string or regex backlist item
}
})

/** @param {Url} url */
const isValidPath = url =>
Expand Down
2 changes: 2 additions & 0 deletions test/examples/config-file/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ test('config file', t => {
verifyFile('bar/index.html', new RegExp('<div id="location">http://spank.test/bar</div>'))
t.assert(exists('link1/index.html'))
t.falsy(exists('link2/index.html'), 'blacklisted links should not be rendered')
t.falsy(exists('link3/index.html'), 'blacklisted links should not be rendered')
t.falsy(exists('link4/index.html'), 'blacklisted links should not be rendered')
})
2 changes: 2 additions & 0 deletions test/examples/config-file/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ document.getElementById('app').innerHTML =
<div id="location">${window.location.href}</div>
<a href="/link1">link1</a>
<a href="/link2">link2</a>
<a href="/link3">link3</a>
<a href="/link4">link4</a>
`
2 changes: 1 addition & 1 deletion test/examples/config-file/spank.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ module.exports = {
'/bar',
'/baz'
],
blacklist: ['/link2']
blacklist: ['/link2', /\/link[3|4]/]
}

0 comments on commit 74a342f

Please sign in to comment.