Commit d61f74ff7b
d61f74ff7be04c2c883a4e103d58c39b274d56b0
parent: 8dc79012ca
Unsigned
Duck <57977673+woducku@users.noreply.github.com> · 2026-10-26 14:31 UTC
auto collapse sidebar folder
Layout: unified · split
docs/.vitepress/configs/index.ts
+6
| @@ -172,6 +172,12 @@ export const shared: UserConfig<DefaultTheme.Config> = { |
| 172 | 172 | replacement: fileURLToPath( |
| 173 | 173 | new URL('../theme/components/NavBarSearch.vue', import.meta.url) |
| 174 | 174 | ) |
| 175 | }, |
| 176 | { |
| 177 | find: /^\.\.\/composables\/sidebar$/, |
| 178 | replacement: fileURLToPath( |
| 179 | new URL('../theme/composables/sidebar.ts', import.meta.url) |
| 180 | ) |
| 175 | 181 | } |
| 176 | 182 | ] |
| 177 | 183 | } |
docs/.vitepress/theme/composables/sidebar.ts
added
+18
| @@ -0,0 +1,18 @@ |
| 1 | import type { DefaultTheme } from 'vitepress' |
| 2 | import { |
| 3 | useSidebarItemControl as useUpstreamSidebarItemControl |
| 4 | } from 'vitepress/dist/client/theme-default/composables/sidebar' |
| 5 | import type { Ref } from 'vue' |
| 6 | import { watch } from 'vue' |
| 7 | |
| 8 | export function useSidebarItemControl(item: Ref<DefaultTheme.SidebarItem>) { |
| 9 | const control = useUpstreamSidebarItemControl(item) |
| 10 | |
| 11 | watch(control.hasActiveLink, (hasActiveLink) => { |
| 12 | if (!hasActiveLink && control.collapsible.value) { |
| 13 | control.collapsed.value = !!item.value.collapsed |
| 14 | } |
| 15 | }) |
| 16 | |
| 17 | return control |
| 18 | } |
docs/.vitepress/theme/shim.d.ts
+17
| @@ -4,5 +4,22 @@ declare module 'mark.js/dist/mark.es6.js' { |
| 4 | 4 | export default mark |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | declare module 'vitepress/dist/client/theme-default/composables/sidebar' { |
| 8 | import type { DefaultTheme } from 'vitepress' |
| 9 | import type { ComputedRef, Ref } from 'vue' |
| 10 | |
| 11 | export function useSidebarItemControl( |
| 12 | item: Ref<DefaultTheme.SidebarItem> |
| 13 | ): { |
| 14 | collapsed: Ref<boolean> |
| 15 | collapsible: ComputedRef<boolean> |
| 16 | isLink: ComputedRef<boolean> |
| 17 | isActiveLink: Ref<boolean> |
| 18 | hasActiveLink: ComputedRef<boolean> |
| 19 | hasChildren: ComputedRef<boolean> |
| 20 | toggle: () => void |
| 21 | } |
| 22 | } |
| 23 | |
| 7 | 24 | declare const __GIT_COMMIT__: string |
| 8 | 25 | declare const __GIT_COMMIT_TS__: number |