diff --git a/packages/valaxy/client/composables/outline/headers.ts b/packages/valaxy/client/composables/outline/headers.ts index 888a1ed8f..db900a7a4 100644 --- a/packages/valaxy/client/composables/outline/headers.ts +++ b/packages/valaxy/client/composables/outline/headers.ts @@ -1,6 +1,8 @@ -import { computed, shallowRef } from 'vue' +import { computed } from 'vue' +import { useRoute } from 'vue-router' import type { DefaultTheme, Header } from 'valaxy/types' import { onContentUpdated } from '../../utils' +import { useOutlineStore } from '../../stores' import { useFrontmatter, useThemeConfig } from '../..' export type MenuItem = Omit & { @@ -68,15 +70,19 @@ function addToParent( export function useOutline() { const frontmatter = useFrontmatter() const themeConfig = useThemeConfig() - const headers = shallowRef([]) + const route = useRoute() + const store = useOutlineStore() + const pageOutline = computed( () => frontmatter.value.outline ?? themeConfig.value.outline, ) + const headers = computed(() => store.$state[route.path] || []) + onContentUpdated(() => { if (pageOutline.value === false) return - headers.value = getHeaders(pageOutline.value) + store.$state[route.path] = getHeaders(pageOutline.value) }) const handleClick = ({ target: el }: Event) => { diff --git a/packages/valaxy/client/stores/index.ts b/packages/valaxy/client/stores/index.ts index e2458f9d0..c2250221e 100644 --- a/packages/valaxy/client/stores/index.ts +++ b/packages/valaxy/client/stores/index.ts @@ -1,3 +1,4 @@ export * from './app' export * from './router' export * from './site' +export * from './outline' diff --git a/packages/valaxy/client/stores/outline.ts b/packages/valaxy/client/stores/outline.ts new file mode 100644 index 000000000..a880f867a --- /dev/null +++ b/packages/valaxy/client/stores/outline.ts @@ -0,0 +1,6 @@ +import { defineStore } from 'pinia' +import type { MenuItem } from 'valaxy' + +export const useOutlineStore = defineStore('OutlineStore', { + state: () => ({} as Record), +})