From ba721e72f997a07ffcad7eaf5efc36db43066e87 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sun, 21 Apr 2024 00:17:02 +0800 Subject: [PATCH] =?UTF-8?q?perf(theme):=20=E4=BC=98=E5=8C=96=20sidebar=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- theme/src/client/components/Sidebar.vue | 6 +++++- .../src/client/components/TransitionDrop.vue | 2 +- theme/src/client/composables/sidebar.ts | 21 ++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/theme/src/client/components/Sidebar.vue b/theme/src/client/components/Sidebar.vue index bee593a0..55e421c2 100644 --- a/theme/src/client/components/Sidebar.vue +++ b/theme/src/client/components/Sidebar.vue @@ -52,7 +52,11 @@ watch( Sidebar Navigation -
+
diff --git a/theme/src/client/components/TransitionDrop.vue b/theme/src/client/components/TransitionDrop.vue index 39e24ed6..83d86774 100644 --- a/theme/src/client/components/TransitionDrop.vue +++ b/theme/src/client/components/TransitionDrop.vue @@ -21,7 +21,7 @@ function setStyle(item: Element) { if (!_transition) { const value = typeof window !== 'undefined' && window.getComputedStyle ? window.getComputedStyle(el).transition : '' - _transition = value && !value.includes('all') ? `${value}, ` : '' + _transition = value && !value.includes('all') ? `${value}, ` : ' ' } el.style.transition = `${_transition}transform ${props.duration}s ease-in-out ${props.delay}s, opacity ${props.duration}s ease-in-out ${props.delay}s` diff --git a/theme/src/client/composables/sidebar.ts b/theme/src/client/composables/sidebar.ts index 16e192cd..52e3dc1f 100644 --- a/theme/src/client/composables/sidebar.ts +++ b/theme/src/client/composables/sidebar.ts @@ -23,7 +23,26 @@ export function getSidebarList(path: string, notesData: NotesData) { const link = Object.keys(notesData).find(link => path.startsWith(normalizePath(link)), ) - return link ? notesData[link] : [] + const sidebar = link ? notesData[link] : [] + + const groups: NotesSidebarItem[] = [] + + let lastGroupIndex: number = 0 + + for (const index in sidebar) { + const item = sidebar[index] + + if (item.items && item.items.length) { + lastGroupIndex = groups.push(item) + continue + } + + if (!groups[lastGroupIndex]) + groups.push({ items: [] }) + + groups[lastGroupIndex]!.items!.push(item) + } + return groups } export function getSidebarFirstLink(sidebar: NotesSidebarItem[]) {