diff --git a/src/client/theme-default/components/VPCarbonAds.vue b/src/client/theme-default/components/VPCarbonAds.vue index d1f669f1..8c2a8743 100644 --- a/src/client/theme-default/components/VPCarbonAds.vue +++ b/src/client/theme-default/components/VPCarbonAds.vue @@ -3,16 +3,16 @@ import { ref, watch, onMounted } from 'vue' import { useData } from 'vitepress' import { useAside } from '../composables/aside.js' -const { theme } = useData() +const { theme, page } = useData() const carbonOptions = theme.value.carbonAds const { isAsideEnabled } = useAside() const container = ref() -let hasInitalized = false +let isInitialized = false function init() { - if (!hasInitalized) { - hasInitalized = true + if (!isInitialized) { + isInitialized = true const s = document.createElement('script') s.id = '_carbonads_js' s.src = `//cdn.carbonads.com/carbon.js?serve=${carbonOptions.code}&placement=${carbonOptions.placement}` @@ -21,6 +21,12 @@ function init() { } } +watch(() => page.value.relativePath, () => { + if (isInitialized && isAsideEnabled.value) { + ;(window as any)._carbonads?.refresh() + } +}) + // no need to account for option changes during dev, we can just // refresh the page if (carbonOptions) {