Skip to content

Commit

Permalink
fix(theme): refresh ads per page navigation (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
posva authored Jan 2, 2023
1 parent fb7a060 commit 8db20fe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/client/theme-default/components/VPCarbonAds.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand All @@ -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) {
Expand Down

0 comments on commit 8db20fe

Please sign in to comment.