@@ -251,17 +251,41 @@ const findRelated = async (current, relativePath, stat, extension = '.html') =>
251
251
return null ;
252
252
} ;
253
253
254
+ const canBeListed = ( excluded , file ) => {
255
+ const slashed = slasher ( file ) ;
256
+ let whether = true ;
257
+
258
+ for ( let mark = 0 ; mark < excluded . length ; mark ++ ) {
259
+ const source = excluded [ mark ] ;
260
+
261
+ if ( sourceMatches ( source , slashed ) ) {
262
+ whether = false ;
263
+ break ;
264
+ }
265
+ }
266
+
267
+ return whether ;
268
+ } ;
269
+
254
270
const renderDirectory = async ( current , relativePath , absolutePath , handlers , config ) => {
255
- const { directoryListing, trailingSlash} = config ;
271
+ const { directoryListing, trailingSlash, unlisted = [ ] } = config ;
256
272
const slashSuffix = typeof trailingSlash === 'boolean' ? ( trailingSlash ? '/' : '' ) : '/' ;
257
273
274
+ const excluded = [
275
+ '.DS_Store' ,
276
+ '.git' ,
277
+ ...unlisted
278
+ ] ;
279
+
258
280
if ( ! applicable ( relativePath , directoryListing , false ) ) {
259
281
return null ;
260
282
}
261
283
262
284
let files = await handlers . readdir ( absolutePath ) ;
263
285
264
- for ( const file of files ) {
286
+ for ( let index = 0 ; index < files . length ; index ++ ) {
287
+ const file = files [ index ] ;
288
+
265
289
const filePath = path . resolve ( absolutePath , file ) ;
266
290
const details = path . parse ( filePath ) ;
267
291
const stats = await handlers . stat ( filePath ) ;
@@ -279,7 +303,12 @@ const renderDirectory = async (current, relativePath, absolutePath, handlers, co
279
303
}
280
304
281
305
details . title = details . base ;
282
- files [ files . indexOf ( file ) ] = details ;
306
+
307
+ if ( canBeListed ( excluded , file ) ) {
308
+ files [ index ] = details ;
309
+ } else {
310
+ delete files [ index ] ;
311
+ }
283
312
}
284
313
285
314
const toRoot = path . relative ( current , absolutePath ) ;
@@ -308,7 +337,7 @@ const renderDirectory = async (current, relativePath, absolutePath, handlers, co
308
337
}
309
338
310
339
return 0 ;
311
- } ) ;
340
+ } ) . filter ( Boolean ) ;
312
341
313
342
// Add parent directory to the head of the sorted files array
314
343
if ( toRoot . length > 0 ) {
0 commit comments