From 03b645e7916db27488c34242a8b419bebb5743f9 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 30 Aug 2024 23:34:23 +0800 Subject: [PATCH] fix(theme): incorrect resolve page path when sidebar matched --- theme/src/client/composables/sidebar.ts | 1 + theme/src/node/prepare/prepareSidebar.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/theme/src/client/composables/sidebar.ts b/theme/src/client/composables/sidebar.ts index f36323a37..92927d594 100644 --- a/theme/src/client/composables/sidebar.ts +++ b/theme/src/client/composables/sidebar.ts @@ -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) diff --git a/theme/src/node/prepare/prepareSidebar.ts b/theme/src/node/prepare/prepareSidebar.ts index 69974f7fb..4d2b7c625 100644 --- a/theme/src/node/prepare/prepareSidebar.ts +++ b/theme/src/node/prepare/prepareSidebar.ts @@ -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