Skip to content

Commit 1179484

Browse files
committedAug 3, 2023
feat(client): allow overriding props on Content
closes #2712
1 parent d7e2254 commit 1179484

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed
 

‎src/client/app/components/Content.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent, h } from 'vue'
2-
import { useRoute } from '../router'
2+
import { useData, useRoute } from 'vitepress'
33
import { contentUpdatedCallbacks } from '../utils'
44

55
const runCbs = () => contentUpdatedCallbacks.forEach((fn) => fn())
@@ -11,14 +11,19 @@ export const Content = defineComponent({
1111
},
1212
setup(props) {
1313
const route = useRoute()
14+
const { site } = useData()
1415
return () =>
15-
h(props.as, { style: { position: 'relative' } }, [
16-
route.component
17-
? h(route.component, {
18-
onVnodeMounted: runCbs,
19-
onVnodeUpdated: runCbs
20-
})
21-
: '404 Page Not Found'
22-
])
16+
h(
17+
props.as,
18+
site.value.contentProps ?? { style: { position: 'relative' } },
19+
[
20+
route.component
21+
? h(route.component, {
22+
onVnodeMounted: runCbs,
23+
onVnodeUpdated: runCbs
24+
})
25+
: '404 Page Not Found'
26+
]
27+
)
2328
}
2429
})

‎src/node/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ export async function resolveSiteData(
235235
themeConfig: userConfig.themeConfig || {},
236236
locales: userConfig.locales || {},
237237
scrollOffset: userConfig.scrollOffset ?? 90,
238-
cleanUrls: !!userConfig.cleanUrls
238+
cleanUrls: !!userConfig.cleanUrls,
239+
contentProps: userConfig.contentProps
239240
}
240241
}
241242

‎src/node/siteConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface UserConfig<ThemeConfig = any>
7070

7171
appearance?: boolean | 'dark'
7272
lastUpdated?: boolean
73+
contentProps?: Record<string, any>
7374

7475
/**
7576
* MarkdownIt options

‎types/shared.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface SiteData<ThemeConfig = any> {
6060
scrollOffset: number | string | string[]
6161
locales: LocaleConfig<ThemeConfig>
6262
localeIndex?: string
63+
contentProps?: Record<string, any>
6364
}
6465

6566
export type HeadConfig =

0 commit comments

Comments
 (0)
Please sign in to comment.