@@ -135,7 +135,13 @@ const dirList = {
135135 }
136136
137137 const format = reply . request . query . format || options . format
138+ const renderFormat = format === 'html' ? 'html' : 'json'
138139 if ( format !== 'html' ) {
140+ if ( typeof options . render === 'function' && options . format !== 'html' ) {
141+ await reply . send ( dirList . render ( entries , route , prefix , options , renderFormat ) )
142+ return
143+ }
144+
139145 if ( options . jsonFormat !== 'extended' ) {
140146 const nameEntries = { dirs : [ ] , files : [ ] }
141147 entries . dirs . forEach ( entry => nameEntries . dirs . push ( entry . name ) )
@@ -148,12 +154,26 @@ const dirList = {
148154 return
149155 }
150156
151- const html = options . render (
152- entries . dirs . map ( entry => dirList . htmlInfo ( entry , route , prefix , options ) ) ,
153- entries . files . map ( entry => dirList . htmlInfo ( entry , route , prefix , options ) ) )
157+ const html = dirList . render ( entries , route , prefix , options , renderFormat )
154158 await reply . type ( 'text/html' ) . send ( html )
155159 } ,
156160
161+ /**
162+ * render directory entries
163+ * @param {ReturnType<typeof dirList.list> } entries directory list entries
164+ * @param {string } route request route
165+ * @param {string } prefix static prefix
166+ * @param {(ListOptionsJsonFormat | ListOptionsHtmlFormat) } options
167+ * @param {'html' | 'json' } format response format
168+ * @return {unknown }
169+ */
170+ render : function ( entries , route , prefix , options , format ) {
171+ return options . render (
172+ entries . dirs . map ( entry => dirList . htmlInfo ( entry , route , prefix , options ) ) ,
173+ entries . files . map ( entry => dirList . htmlInfo ( entry , route , prefix , options ) ) ,
174+ format )
175+ } ,
176+
157177 /**
158178 * provide the html information about entry and route, to get name and full route
159179 * @param entry file or dir name and stats
0 commit comments