@@ -184,9 +184,12 @@ const normalizeOptions = (options) => {
184184 * @param {Object } data
185185 *
186186 * @return {Mixed } String or Null
187+ *
188+ * @todo embed regexparam in this pkg: this method contains too many workarounds
189+ * to patch regexparam's lack of customization
187190 */
188191const replace = ( { pattern, ...options } , data ) => {
189- // regexparam has logic that interprets a dot as start of an extension name
192+ // regexparam.parse has logic that interprets a dot as start of an extension name
190193 // we don't want this here, so we replace it temporarily with a NUL char
191194 const remapped = pattern . replace ( / \. / g, '\0' )
192195 const { keys } = route . parse ( remapped )
@@ -213,8 +216,14 @@ const replace = ({ pattern, ...options }, data) => {
213216 }
214217
215218 let transformed = route . inject ( remapped , ret )
219+
220+ // avoid index/index permalink
216221 if ( path . basename ( transformed ) === path . basename ( options . directoryIndex , path . extname ( options . directoryIndex ) ) )
217222 transformed = path . dirname ( transformed )
223+
224+ // restore dots that were not part of a :pattern.key keypath (and have not been restored yet)
225+ transformed = transformed . replace ( / \0 / g, '.' )
226+
218227 // handle absolute paths
219228 if ( transformed . startsWith ( '/' ) ) return transformed . slice ( 1 )
220229 return transformed
@@ -274,7 +283,7 @@ function permalinks(options) {
274283 const permalinkTransformContext = { ...normalizedOptions , ...defaultLinkset , ...linkset }
275284 if ( hasOwnPermalinkDeclaration ) permalinkTransformContext . pattern = fileSpecificPermalink
276285
277- debug ( 'Applying pattern: "%s" to file: "%s"' , linkset . pattern , file )
286+ debug ( 'Applying pattern: "%s" to file: "%s"' , permalinkTransformContext . pattern , file )
278287
279288 let ppath
280289
@@ -310,14 +319,10 @@ function permalinks(options) {
310319 // files matched for permalinking that are already at their destination (/index.html) have an empty string permalink ('')
311320 // normalize('') results in '.', which we don't want here
312321 let permalink = ppath . length ? normalize ( ppath . replace ( / \\ / g, '/' ) ) : ppath
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 , './' )
319- data . permalink = permalink
320- }
322+
323+ // only add trailingSlash when permalink !== '' (=directoryIndex) & not a fixed permalink
324+ if ( permalink && normalizedOptions . trailingSlash && ! hasOwnPermalinkDeclaration ) permalink = join ( permalink , './' )
325+ data . permalink = permalink
321326
322327 delete files [ file ]
323328 files [ out ] = data
0 commit comments