Skip to content

Commit

Permalink
Fixes #120: default linkset options should be overwritten by other li…
Browse files Browse the repository at this point in the history
…nksets

Credit to @depuits for fixing this issue
  • Loading branch information
webketje committed Dec 18, 2021
1 parent 21bc858 commit 48b4fa2
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const plugin = options => {
if (!html(file)) return;
if (data.permalink === false) return;

const linkset = Object.assign({}, findLinkset(data), defaultLinkset);
const linkset = Object.assign({}, defaultLinkset, findLinkset(data));
debug('applying pattern: %s to file: %s', linkset.pattern, file);

let ppath = replace(linkset.pattern, data, linkset) || resolve(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
other
4 changes: 4 additions & 0 deletions test/fixtures/linkset-overwrite-default/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: test
---
other
5 changes: 5 additions & 0 deletions test/fixtures/linkset-overwrite-default/src/one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: one post
overwrite: true
---
one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
two
5 changes: 5 additions & 0 deletions test/fixtures/linkset-rule-precedence/src/first.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: one
bothFilesHaveThisProperty: true
---
one
5 changes: 5 additions & 0 deletions test/fixtures/linkset-rule-precedence/src/second.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: two
bothFilesHaveThisProperty: true
---
two
35 changes: 34 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,40 @@ const fixtures = [
},
pattern: ':title'
}
}
},
{
message:
'should overwrite default linkset options with specific linkset options',
folder: 'linkset-overwrite-default',
options: {
pattern: ':title',
linksets: [
{
match: { overwrite: true },
pattern: 'overwritten/:title'
}
]
}
},
{
message:
'should apply the first linkset when multiple linksets match the same file',
folder: 'linkset-rule-precedence',
options: {
pattern: ':title',
linksets: [
{
match: { bothFilesHaveThisProperty: true },
pattern: 'first/:title'
},
{
match: { bothFilesHaveThisProperty: true },
pattern: 'second/:title'
}
]
}
},

];

describe('@metalsmith/permalinks', () => {
Expand Down

0 comments on commit 48b4fa2

Please sign in to comment.