Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update navigation on file update/remove #315

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/core/runtime/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 }) {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down