@@ -268,10 +268,11 @@ function permalinks(options) {
268268 }
269269
270270 const data = files [ file ]
271- const hasOwnPermalinkDeclaration = ! ! data . permalink
271+ const fileSpecificPermalink = data . permalink
272+ const hasOwnPermalinkDeclaration = ! ! fileSpecificPermalink
272273 const linkset = findLinkset ( data , file , metalsmith )
273274 const permalinkTransformContext = { ...normalizedOptions , ...defaultLinkset , ...linkset }
274- if ( hasOwnPermalinkDeclaration ) permalinkTransformContext . pattern = data . permalink
275+ if ( hasOwnPermalinkDeclaration ) permalinkTransformContext . pattern = fileSpecificPermalink
275276
276277 debug ( 'Applying pattern: "%s" to file: "%s"' , linkset . pattern , file )
277278
@@ -309,12 +310,12 @@ function permalinks(options) {
309310 // files matched for permalinking that are already at their destination (/index.html) have an empty string permalink ('')
310311 // normalize('') results in '.', which we don't want here
311312 let permalink = ppath . length ? normalize ( ppath ) : ppath
312- if ( permalink . length && normalizedOptions . trailingSlash ) {
313- permalink = join ( permalink , './' )
314- }
315-
316- // contrary to the 2.x "path" property, the permalink property does not override previously set file metadata
317- if ( ! hasOwnPermalinkDeclaration ) {
313+ // only rewrite data.permalink when a file-specific permalink contains :pattern placeholders
314+ if ( hasOwnPermalinkDeclaration ) {
315+ if ( permalink !== fileSpecificPermalink ) data . permalink = permalink
316+ } else {
317+ // only add trailingSlash when permalink !== ''
318+ if ( permalink && normalizedOptions . trailingSlash ) permalink = join ( permalink , './' )
318319 data . permalink = permalink
319320 }
320321
0 commit comments