@@ -200,6 +200,7 @@ export function resolveMatchingConfig (regularPath, config) {
200
200
config : config
201
201
}
202
202
}
203
+
203
204
for ( const base in config ) {
204
205
if ( ensureEndingSlash ( regularPath ) . indexOf ( encodeURI ( base ) ) === 0 ) {
205
206
return {
@@ -217,6 +218,29 @@ function ensureEndingSlash (path) {
217
218
: path + '/'
218
219
}
219
220
221
+ const baseMap = new Map ( )
222
+ /**
223
+ * handle multilevel sidebar base config
224
+ * @param {* } item
225
+ * @param {* } base
226
+ * @param {* } groupDepth
227
+ * @returns
228
+ */
229
+ function resolveBase ( item , base , groupDepth ) {
230
+ if ( groupDepth <= 2 ) {
231
+ ! baseMap . has ( groupDepth . toString ( ) ) && baseMap . set ( groupDepth . toString ( ) , base )
232
+ return base
233
+ }
234
+
235
+ if ( ! baseMap . has ( groupDepth . toString ( ) ) ) {
236
+ const prev = baseMap . get ( ( groupDepth - 1 ) . toString ( ) )
237
+ baseMap . set ( groupDepth . toString ( ) , `${ prev + item . title } \/` )
238
+ return baseMap . get ( groupDepth . toString ( ) )
239
+ } else {
240
+ return baseMap . get ( groupDepth . toString ( ) )
241
+ }
242
+ }
243
+
220
244
function resolveItem ( item , pages , base , groupDepth = 1 ) {
221
245
if ( typeof item === 'string' ) {
222
246
return resolvePage ( pages , item , base )
@@ -237,7 +261,7 @@ function resolveItem (item, pages, base, groupDepth = 1) {
237
261
title : item . title ,
238
262
sidebarDepth : item . sidebarDepth ,
239
263
initialOpenGroupIndex : item . initialOpenGroupIndex ,
240
- children : children . map ( child => resolveItem ( child , pages , base , groupDepth + 1 ) ) ,
264
+ children : children . map ( child => resolveItem ( child , pages , resolveBase ( item , base , groupDepth + 1 ) , groupDepth + 1 ) ) ,
241
265
collapsable : item . collapsable !== false
242
266
}
243
267
}
0 commit comments