Skip to content

Commit

Permalink
feat(client): allow overriding props on Content
Browse files Browse the repository at this point in the history
closes #2712
  • Loading branch information
brc-dd committed Aug 3, 2023
1 parent d7e2254 commit 1179484
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
23 changes: 14 additions & 9 deletions src/client/app/components/Content.ts
@@ -1,5 +1,5 @@
import { defineComponent, h } from 'vue'
import { useRoute } from '../router'
import { useData, useRoute } from 'vitepress'
import { contentUpdatedCallbacks } from '../utils'

const runCbs = () => contentUpdatedCallbacks.forEach((fn) => fn())
Expand All @@ -11,14 +11,19 @@ export const Content = defineComponent({
},
setup(props) {
const route = useRoute()
const { site } = useData()
return () =>
h(props.as, { style: { position: 'relative' } }, [
route.component
? h(route.component, {
onVnodeMounted: runCbs,
onVnodeUpdated: runCbs
})
: '404 Page Not Found'
])
h(
props.as,
site.value.contentProps ?? { style: { position: 'relative' } },
[
route.component
? h(route.component, {
onVnodeMounted: runCbs,
onVnodeUpdated: runCbs
})
: '404 Page Not Found'
]
)
}
})
3 changes: 2 additions & 1 deletion src/node/config.ts
Expand Up @@ -235,7 +235,8 @@ export async function resolveSiteData(
themeConfig: userConfig.themeConfig || {},
locales: userConfig.locales || {},
scrollOffset: userConfig.scrollOffset ?? 90,
cleanUrls: !!userConfig.cleanUrls
cleanUrls: !!userConfig.cleanUrls,
contentProps: userConfig.contentProps
}
}

Expand Down
1 change: 1 addition & 0 deletions src/node/siteConfig.ts
Expand Up @@ -70,6 +70,7 @@ export interface UserConfig<ThemeConfig = any>

appearance?: boolean | 'dark'
lastUpdated?: boolean
contentProps?: Record<string, any>

/**
* MarkdownIt options
Expand Down
1 change: 1 addition & 0 deletions types/shared.d.ts
Expand Up @@ -60,6 +60,7 @@ export interface SiteData<ThemeConfig = any> {
scrollOffset: number | string | string[]
locales: LocaleConfig<ThemeConfig>
localeIndex?: string
contentProps?: Record<string, any>
}

export type HeadConfig =
Expand Down

0 comments on commit 1179484

Please sign in to comment.