@@ -113,12 +113,27 @@ async function sidebarItemsFromAuto(
113113 project : ProjectContext ,
114114 auto : boolean | string | string [ ] ,
115115) : Promise < SidebarItem [ ] > {
116+ // is this a single directory that exists
117+ const isAutoDir = typeof ( auto ) === "string" &&
118+ ! ! auto . match ( / ^ [ ^ \* ] + $ / ) &&
119+ safeExistsSync ( join ( project . dir , auto ) ) ;
120+
116121 // list of globs from auto
117122 const globs : string [ ] = globsFromAuto ( project , auto ) ;
118123
119124 // scan for inputs and organize them into heirarchical nodes
120125 const entries : Entry [ ] = [ ] ;
121126 for ( const nodeSet of autoSidebarNodes ( project , globs ) ) {
127+ // if this is an auto-dir that has an index page inside it
128+ // then re-shuffle things a bit
129+ if ( isAutoDir ) {
130+ const root = nodeSet . root . split ( "/" ) ;
131+ nodeSet . root = root . slice ( 0 , - 1 ) . join ( "/" ) ;
132+ nodeSet . nodes = {
133+ [ root . slice ( - 1 ) [ 0 ] ] : nodeSet . nodes ,
134+ } ;
135+ }
136+
122137 entries . push (
123138 ...await nodesToEntries (
124139 project ,
@@ -234,9 +249,6 @@ async function nodesToEntries(
234249
235250 // if there is an index file in the root then remove it
236251 // (as the higher level section handler will find it)
237- const findIndexFile = ( ( nds : SidebarNodes ) => {
238- return Object . keys ( nds ) . find ( ( input ) => / ^ i n d e x \. \w + $ / . test ( input ) ) ;
239- } ) ;
240252 const indexFile = findIndexFile ( nodes ) ;
241253 if ( indexFile ) {
242254 delete nodes [ indexFile ] ;
@@ -292,6 +304,10 @@ async function nodesToEntries(
292304 return entries . sort ( sortEntries ) ;
293305}
294306
307+ function findIndexFile ( nodes : SidebarNodes ) {
308+ return Object . keys ( nodes ) . find ( ( input ) => / ^ i n d e x \. \w + $ / . test ( input ) ) ;
309+ }
310+
295311function sortEntries ( a : Entry , b : Entry ) {
296312 const titleOrder = a . title . toLocaleUpperCase ( ) . localeCompare (
297313 b . title . toLocaleUpperCase ( ) ,
0 commit comments