Skip to content

Commit

Permalink
fix: don't require _options for urlParameters transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin committed Oct 1, 2022
1 parent c43d1e5 commit 19ffe0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/transformers/urlParameters.js
Expand Up @@ -6,11 +6,11 @@ module.exports = async (html, config = {}, direct = false) => {
const urlParameters = direct ? config : get(config, 'urlParameters', {})

if (!isEmpty(urlParameters)) {
const {_options, ...parameters} = urlParameters
const tags = _options.tags ?? ['a']
const strict = _options.strict ?? true
const qs = _options.qs ?? {encode: false}
const posthtmlOptions = get(config, 'build.posthtml.options', {})
const {_options, ...parameters} = urlParameters
const tags = get(_options, 'tags', ['a'])
const strict = get(_options, 'strict', true)
const qs = get(_options, 'qs', {encode: false})

return posthtml([urlParams({parameters, tags, qs, strict})]).process(html, posthtmlOptions).then(result => result.html)
}
Expand Down
25 changes: 20 additions & 5 deletions test/test-transformers.js
Expand Up @@ -315,20 +315,35 @@ test('filters (postcss)', async t => {
})

test('url parameters', async t => {
const html = await Maizzle.addURLParams(
const simple = await Maizzle.addURLParams(
`<a href="https://example.com">test</a>
<link href="https://foo.bar">`,
{
bar: 'baz',
qix: 'qux'
}
)

const withOptions = await Maizzle.addURLParams(
`<a href="example.com">test</a>
<link href="https://foo.bar">`,
{
_options: {
tags: ['a[href*="example"]'],
strict: false
strict: false,
qs: {
encode: true
}
},
bar: 'baz',
qix: 'qux'
foo: '@Bar@',
bar: 'baz'
}
)

t.is(html, `<a href="example.com?bar=baz&qix=qux">test</a>
t.is(simple, `<a href="https://example.com?bar=baz&qix=qux">test</a>
<link href="https://foo.bar">`)

t.is(withOptions, `<a href="example.com?bar=baz&foo=%40Bar%40">test</a>
<link href="https://foo.bar">`)
})

Expand Down

0 comments on commit 19ffe0c

Please sign in to comment.