@@ -252,7 +252,7 @@ const findRelated = async (current, relativePath, stat, extension = '.html') =>
252
252
253
253
const renderDirectory = async ( current , relativePath , absolutePath , handlers , config ) => {
254
254
const { directoryListing, trailingSlash} = config ;
255
- const slashSuffix = trailingSlash === true ? '/' : '' ;
255
+ const slashSuffix = typeof trailingSlash === 'boolean' ? ( trailingSlash ? '/' : '' ) : '/ ';
256
256
257
257
if ( ! applicable ( relativePath , directoryListing , false ) ) {
258
258
return null ;
@@ -281,8 +281,9 @@ const renderDirectory = async (current, relativePath, absolutePath, handlers, co
281
281
files [ files . indexOf ( file ) ] = details ;
282
282
}
283
283
284
- const directory = path . join ( path . basename ( current ) , relativePath , '/' ) ;
285
- const pathParts = directory . split ( path . sep ) ;
284
+ const toRoot = path . relative ( current , absolutePath ) ;
285
+ const directory = path . join ( path . basename ( current ) , toRoot , slashSuffix ) ;
286
+ const pathParts = directory . split ( path . sep ) . filter ( Boolean ) ;
286
287
287
288
// Sort to list directories first, then sort alphabetically
288
289
files = files . sort ( ( a , b ) => {
@@ -309,8 +310,6 @@ const renderDirectory = async (current, relativePath, absolutePath, handlers, co
309
310
} ) ;
310
311
311
312
// Add parent directory to the head of the sorted files array
312
- const toRoot = path . relative ( absolutePath , current ) ;
313
-
314
313
if ( toRoot . length > 0 ) {
315
314
const directoryPath = [ ...pathParts ] . slice ( 1 ) ;
316
315
const relative = path . join ( '/' , ...directoryPath , '..' , slashSuffix ) ;
@@ -323,26 +322,23 @@ const renderDirectory = async (current, relativePath, absolutePath, handlers, co
323
322
}
324
323
325
324
const paths = [ ] ;
326
- pathParts . pop ( ) ;
327
325
328
- for ( const part in pathParts ) {
329
- if ( ! { } . hasOwnProperty . call ( pathParts , part ) ) {
330
- continue ;
331
- }
326
+ for ( let index = 0 ; index < pathParts . length ; index ++ ) {
327
+ const parents = [ ] ;
328
+ const isLast = index === ( pathParts . length - 1 ) ;
332
329
333
330
let before = 0 ;
334
- const parents = [ ] ;
335
331
336
- while ( before <= part ) {
332
+ while ( before <= index ) {
337
333
parents . push ( pathParts [ before ] ) ;
338
334
before ++ ;
339
335
}
340
336
341
337
parents . shift ( ) ;
342
338
343
339
paths . push ( {
344
- name : pathParts [ part ] ,
345
- url : parents . join ( '/' )
340
+ name : pathParts [ index ] + ( isLast ? slashSuffix : '/' ) ,
341
+ url : index === 0 ? '' : parents . join ( '/' ) + slashSuffix
346
342
} ) ;
347
343
}
348
344
0 commit comments