fix(theme): incorrect resolve page path when sidebar matched

This commit is contained in:
pengzhanbo 2024-08-30 23:34:23 +08:00
parent 2443f99f46
commit 03b645e791
2 changed files with 3 additions and 2 deletions

View File

@ -95,6 +95,7 @@ export function getSidebar(routePath: string, routeLocal: string): ResolvedSideb
return resolveSidebarItems(_sidebar, routeLocal)
}
else if (isPlainObject(_sidebar)) {
routePath = decodeURIComponent(routePath)
const dir
= Object.keys(_sidebar)
.sort((a, b) => b.split('/').length - a.split('/').length)

View File

@ -93,8 +93,8 @@ function getAutoDirSidebar(
while (nowIndex < maxIndex) {
pages = pages.sort((prev, next) => {
const pi = prev.splitPath?.[nowIndex]?.match(/(\d+)\.(?=[^/]+$)/)?.[1]
const ni = next.splitPath?.[nowIndex]?.match(/(\d+)\.(?=[^/]+$)/)?.[1]
const pi = prev.splitPath?.[nowIndex]?.match(/(?:(\d+)\.)?(?=[^/]+$)/)?.[1]
const ni = next.splitPath?.[nowIndex]?.match(/(?:(\d+)\.)?(?=[^/]+$)/)?.[1]
if (!pi || !ni)
return 0
return Number.parseFloat(pi) < Number.parseFloat(ni) ? -1 : 1