Skip to content

Commit

Permalink
rehype-minify-url: fix link[rel=canonical]
Browse files Browse the repository at this point in the history
Previously the `[href]` of a `link[rel=canonical]` was minified.
It shouldn’t be.
  • Loading branch information
wooorm committed Sep 11, 2021
1 parent 28a3f72 commit 190ced9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/rehype-minify-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export default function rehypeMinifyUrl(options) {
if (
hasProperty(node, prop) &&
own.call(urlAttributes, prop) &&
isElement(node, urlAttributes[prop])
isElement(node, urlAttributes[prop]) &&
!(
node.tagName === 'link' &&
prop === 'href' &&
Array.isArray(props.rel) &&
props.rel.includes('canonical')
)
) {
props[prop] = minify(props[prop], relate)
}
Expand Down
23 changes: 23 additions & 0 deletions packages/rehype-minify-url/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ test('rehype-minify-url', (t) => {
u('root', [{type: 'element', tagName: 'a', children: []}])
)

t.deepEqual(
rehype()
.use(min, options)
.runSync(
u('root', [
{
type: 'element',
tagName: 'link',
properties: {href: options.from, rel: ['canonical']},
children: []
}
])
),
u('root', [
{
type: 'element',
tagName: 'link',
properties: {href: options.from, rel: ['canonical']},
children: []
}
])
)

t.deepEqual(
rehype()
.use(() => (_, file) => {
Expand Down

0 comments on commit 190ced9

Please sign in to comment.