Skip to content

Commit

Permalink
feat: support Theme.extends
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 7, 2023
1 parent 868a586 commit f39b6a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/client/app/index.ts
Expand Up @@ -7,7 +7,7 @@ import {
onMounted,
watchEffect
} from 'vue'
import Theme from '@theme/index'
import RawTheme from '@theme/index'
import { inBrowser, pathToFile } from './utils.js'
import { type Router, RouterSymbol, createRouter } from './router.js'
import { siteDataRef, useData } from './data.js'
Expand All @@ -19,6 +19,23 @@ import { ClientOnly } from './components/ClientOnly.js'
import { useCopyCode } from './composables/copyCode.js'
import { useCodeGroups } from './composables/codeGroups.js'

function resolveThemeExtends(theme: typeof RawTheme): typeof RawTheme {
if (theme.extends) {
const base = resolveThemeExtends(theme.extends)
return {
...base,
...theme,
enhanceApp(ctx) {
if (base.enhanceApp) base.enhanceApp(ctx)
if (theme.enhanceApp) theme.enhanceApp(ctx)
}
}
}
return theme
}

const Theme = resolveThemeExtends(RawTheme)

const VitePressApp = defineComponent({
name: 'VitePressApp',
setup() {
Expand Down
1 change: 1 addition & 0 deletions src/client/app/theme.ts
Expand Up @@ -11,6 +11,7 @@ export interface EnhanceAppContext {
export interface Theme {
Layout: Component
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
extends?: Theme

/**
* @deprecated can be replaced by wrapping layout component
Expand Down

0 comments on commit f39b6a9

Please sign in to comment.