feat(client): allow overriding props on Content

closes #2712
pull/2723/head
Divyansh Singh 2 years ago
parent d7e225473b
commit 1179484432

@ -1,5 +1,5 @@
import { defineComponent, h } from 'vue' import { defineComponent, h } from 'vue'
import { useRoute } from '../router' import { useData, useRoute } from 'vitepress'
import { contentUpdatedCallbacks } from '../utils' import { contentUpdatedCallbacks } from '../utils'
const runCbs = () => contentUpdatedCallbacks.forEach((fn) => fn()) const runCbs = () => contentUpdatedCallbacks.forEach((fn) => fn())
@ -11,14 +11,19 @@ export const Content = defineComponent({
}, },
setup(props) { setup(props) {
const route = useRoute() const route = useRoute()
const { site } = useData()
return () => return () =>
h(props.as, { style: { position: 'relative' } }, [ h(
props.as,
site.value.contentProps ?? { style: { position: 'relative' } },
[
route.component route.component
? h(route.component, { ? h(route.component, {
onVnodeMounted: runCbs, onVnodeMounted: runCbs,
onVnodeUpdated: runCbs onVnodeUpdated: runCbs
}) })
: '404 Page Not Found' : '404 Page Not Found'
]) ]
)
} }
}) })

@ -235,7 +235,8 @@ export async function resolveSiteData(
themeConfig: userConfig.themeConfig || {}, themeConfig: userConfig.themeConfig || {},
locales: userConfig.locales || {}, locales: userConfig.locales || {},
scrollOffset: userConfig.scrollOffset ?? 90, scrollOffset: userConfig.scrollOffset ?? 90,
cleanUrls: !!userConfig.cleanUrls cleanUrls: !!userConfig.cleanUrls,
contentProps: userConfig.contentProps
} }
} }

@ -70,6 +70,7 @@ export interface UserConfig<ThemeConfig = any>
appearance?: boolean | 'dark' appearance?: boolean | 'dark'
lastUpdated?: boolean lastUpdated?: boolean
contentProps?: Record<string, any>
/** /**
* MarkdownIt options * MarkdownIt options

1
types/shared.d.ts vendored

@ -60,6 +60,7 @@ export interface SiteData<ThemeConfig = any> {
scrollOffset: number | string | string[] scrollOffset: number | string | string[]
locales: LocaleConfig<ThemeConfig> locales: LocaleConfig<ThemeConfig>
localeIndex?: string localeIndex?: string
contentProps?: Record<string, any>
} }
export type HeadConfig = export type HeadConfig =

Loading…
Cancel
Save