diff --git a/src/core/runtime/composables/navigation.ts b/src/core/runtime/composables/navigation.ts index c74e38827..35f5c7e2c 100644 --- a/src/core/runtime/composables/navigation.ts +++ b/src/core/runtime/composables/navigation.ts @@ -11,13 +11,16 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon if (!state.navigation) state.navigation = {} // compute `currentNav` on every route change + const fetchCounter = ref(0) const path = ref(route.path) - const currentNav = computed(() => - get({ + const currentNav = computed(() => { + // eslint-disable-next-line no-unused-expressions + fetchCounter.value + return get({ locale: app.i18n.locale, from: path.value }) - ) + }) app.router.beforeEach((to: any, __: any, next: any) => { path.value = to.path next() @@ -26,6 +29,7 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon const fetchNavigation = async () => { const { body } = await api.data('/docus/navigation/' + locale) state.navigation[locale] = body + fetchCounter.value += 1 } function get({ depth, locale, from }: { depth?: number; locale?: string; from?: string }) { @@ -113,6 +117,12 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon return withTrailingSlash(path) === withTrailingSlash(context.$contentLocalePath(to)) } + window.onNuxtReady($nuxt => { + $nuxt.$on('content:update', () => { + fetchNavigation() + }) + }) + return { getPageTemplate, fetchNavigation, diff --git a/src/core/storage.ts b/src/core/storage.ts index a6b75bc97..44325db5c 100644 --- a/src/core/storage.ts +++ b/src/core/storage.ts @@ -91,9 +91,11 @@ export const docusDriver = defineDriver((options: DriverOptions) => { const content = await fs.getItem(key) await parseAndIndex(key, content) - - callHook('docus:storage:updated', { event, key }) } + if (event === 'remove') { + await items.removeWhere(doc => doc.key === key) + } + callHook('docus:storage:updated', { event, key }) callback(event, key) }) }