Skip to content
Merged
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
24 changes: 17 additions & 7 deletions src/runtime/components/content/ContentToc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ContentTocSlots<T extends ContentTocLink = ContentTocLink> {
</script>

<script setup lang="ts" generic="T extends ContentTocLink">
import { computed } from 'vue'
import { computed, onUnmounted } from 'vue'
import { CollapsibleRoot, CollapsibleTrigger, CollapsibleContent, useForwardPropsEmits } from 'reka-ui'
import { reactivePick, createReusableTemplate } from '@vueuse/core'
import { useRouter, useAppConfig, useNuxtApp } from '#imports'
Expand Down Expand Up @@ -193,13 +193,23 @@ const circuitMaskStyle = computed(() => {

const nuxtApp = useNuxtApp()

nuxtApp.hooks.hook('page:loading:end', () => {
const headings = Array.from(document.querySelectorAll('h2, h3'))
updateHeadings(headings)
})
nuxtApp.hooks.hook('page:transition:finish', () => {
const headings = Array.from(document.querySelectorAll('h2, h3'))
function refreshHeadings() {
const flatLinks = flattenLinks(props.links || [])
if (!flatLinks.length) {
updateHeadings([])
return
}
const selector = flatLinks.map(l => `#${CSS.escape(l.id)}`).join(', ')
const headings = Array.from(document.querySelectorAll(selector))
updateHeadings(headings)
}

const offLoadingEnd = nuxtApp.hooks.hook('page:loading:end', refreshHeadings)
const offTransitionFinish = nuxtApp.hooks.hook('page:transition:finish', refreshHeadings)

onUnmounted(() => {
offLoadingEnd()
offTransitionFinish()
})
</script>

Expand Down
Loading