Skip to content

Commit

Permalink
Improve debug & error message clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Nov 6, 2024
1 parent 76a1349 commit 3b754ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function permalinks(options) {

return function permalinks(files, metalsmith, done) {
const debug = metalsmith.debug('@metalsmith/permalinks')
debug.info('Running with options: %O', normalizedOptions)
debug.info('Running with options (normalized): %O', normalizedOptions)

if (normalizedOptions.relative || normalizedOptions.linksets.find((ls) => ls && ls.relative)) {
return done(new Error('The "relative" option is no longer supported.'))
Expand All @@ -265,13 +265,11 @@ function permalinks(options) {
.forEach((file) => {
const data = files[file]
const hasOwnPermalinkDeclaration = !!data.permalink
debug('checking file: %s', file)

const linkset = findLinkset(data, file, metalsmith)
const permalinkTransformContext = { ...normalizedOptions, ...defaultLinkset, ...linkset }
if (hasOwnPermalinkDeclaration) permalinkTransformContext.pattern = data.permalink

debug('applying pattern: %s to file: %s', linkset.pattern, file)
debug('Applying pattern: "%s" to file: "%s"', linkset.pattern, file)

let ppath

Expand All @@ -292,7 +290,7 @@ function permalinks(options) {

// invalid on Windows, but best practice not to use them anyway
if (new RegExp(invalidPathChars).test(ppath)) {
const msg = `Filepath "${file}" contains invalid filepath characters (one of :|<>"*?) after resolving as linkset pattern "${linkset.pattern}"`
const msg = `Permalink "${ppath}" for file "${file}" contains invalid filepath characters (one of :|<>"*?) after resolution with linkset pattern "${linkset.pattern}"`
debug.error(msg)
return done(new Error(msg))
}
Expand All @@ -315,6 +313,8 @@ function permalinks(options) {

delete files[file]
files[out] = data

debug('Moved file "%s" to "%s" (permalink = "%s")', file, out, data.permalink)
})

done()
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe('@metalsmith/permalinks', () => {
try {
assert.strictEqual(
err.message,
'Filepath "post.html" contains invalid filepath characters (one of :|<>"*?) after resolving as linkset pattern ":title"'
'Permalink ":title" for file "post.html" contains invalid filepath characters (one of :|<>"*?) after resolution with linkset pattern ":title"'
)
done()
} catch (err) {
Expand Down

0 comments on commit 3b754ab

Please sign in to comment.