-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathContent.ts
More file actions
53 lines (48 loc) · 1.38 KB
/
Content.ts
File metadata and controls
53 lines (48 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { computed, defineAsyncComponent, defineComponent, h } from 'vue'
import { usePageComponent } from '../composables/index.js'
import { contentUpdatedCallbacks } from '../internal/contentUpdatedCallbacks'
import { resolveRoute } from '../router/index.js'
import type { ContentUpdatedReason } from '../types/index.js'
/**
* Execute all callbacks registered via `onContentUpdated`.
*
* @internal
*/
const runContentUpdatedCallbacks = (reason: ContentUpdatedReason): void => {
contentUpdatedCallbacks.forEach((fn) => fn(reason))
}
/**
* Markdown rendered content
*/
export const Content = defineComponent({
name: 'Content',
props: {
path: {
type: String,
required: false,
default: '',
},
},
setup(props) {
const pageComponent = usePageComponent()
const ContentComponent = computed(() => {
if (!props.path) return pageComponent.value
const route = resolveRoute(props.path)
return defineAsyncComponent(async () =>
route.loader().then((module) => module.default),
)
})
return () =>
h(ContentComponent.value, {
onVnodeMounted: () => {
runContentUpdatedCallbacks('mounted')
},
onVnodeUpdated: () => {
runContentUpdatedCallbacks('updated')
},
onVnodeBeforeUnmount: () => {
runContentUpdatedCallbacks('beforeUnmount')
},
})
},
})