diff --git a/src/client/theme-default/support/sidebar.ts b/src/client/theme-default/support/sidebar.ts index 1ae5b390..426abc2a 100644 --- a/src/client/theme-default/support/sidebar.ts +++ b/src/client/theme-default/support/sidebar.ts @@ -30,11 +30,18 @@ export function getSidebar( const dir = Object.keys(_sidebar) .sort((a, b) => { + // longer dir link has higher priority return b.split('/').length - a.split('/').length }) .find((dir) => { + const dirWithStartingSlash = ensureStartingSlash(dir) // make sure the multi sidebar key starts with slash too - return path.startsWith(ensureStartingSlash(dir)) + if (path.startsWith(dirWithStartingSlash)) { + // "/" match everything and it has lowest priority + if (dirWithStartingSlash === '/') return true + const remains = path.replace(dirWithStartingSlash, '') + if (remains.startsWith('/') || remains === '') return true + } }) const sidebar = dir ? (_sidebar[dir] ?? []) : []