feat: allow specifying a setup function in Theme

pull/1136/head
Divyansh Singh 3 years ago
parent 7ad269d806
commit 8d101ec66f

@ -2,6 +2,7 @@ import {
App, App,
createApp as createClientApp, createApp as createClientApp,
createSSRApp, createSSRApp,
defineComponent,
h, h,
onMounted, onMounted,
watch watch
@ -18,7 +19,7 @@ import { ClientOnly } from './components/ClientOnly'
const NotFound = Theme.NotFound || (() => '404 Not Found') const NotFound = Theme.NotFound || (() => '404 Not Found')
const VitePressApp = { const VitePressApp = defineComponent({
name: 'VitePressApp', name: 'VitePressApp',
setup() { setup() {
const { site } = useData() const { site } = useData()
@ -38,9 +39,11 @@ const VitePressApp = {
// in prod mode, enable intersectionObserver based pre-fetch // in prod mode, enable intersectionObserver based pre-fetch
usePrefetch() usePrefetch()
} }
if (Theme.setup) Theme.setup()
return () => h(Theme.Layout) return () => h(Theme.Layout)
} }
} })
export function createApp() { export function createApp() {
const router = newRouter() const router = newRouter()

@ -12,4 +12,5 @@ export interface Theme {
Layout: Component Layout: Component
NotFound?: Component NotFound?: Component
enhanceApp?: (ctx: EnhanceAppContext) => void enhanceApp?: (ctx: EnhanceAppContext) => void
setup?: () => void
} }

Loading…
Cancel
Save