Skip to content

Commit b8e892e

Browse files
committed
feat: support customizing default theme via slots
Example: ```js // .vitepress/theme/index.js import { h } from 'vue' import { defaultTheme } from 'vitepress' const BaseLayout = defaultTheme.Layout defaultTheme.Layout = () => { return h(BaseLayout, null, { 'page-top-ads': () => h('h2', 'top ads!'), 'page-bottom-ads': () => h('h2', 'bottom ads!'), }) } export default defaultTheme ```
1 parent 7dd5c24 commit b8e892e

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

src/client/app/exports.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// so the user can do `import { useRoute, useSiteData } from 'vitepress'`
33

44
// generic types
5-
export type { SiteData, PageData } from '/@types/shared'
65
export type { Router, Route } from './router'
76

87
// theme types
@@ -25,3 +24,6 @@ import { ComponentOptions } from 'vue'
2524
import _Debug from './components/Debug.vue'
2625
const Debug = _Debug as ComponentOptions
2726
export { Debug }
27+
28+
// default theme
29+
export { default as defaultTheme } from '/@default-theme/index'

src/client/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"types": ["vite"],
99
"paths": {
1010
"/@theme/*": ["theme-default/*"],
11+
"/@default-theme/*": ["theme-default/*"],
1112
"/@shared/*": ["shared/*"],
1213
"/@types/*": ["../../types/*"],
1314
"vitepress": ["app/exports.ts"]

src/node/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import fs from 'fs-extra'
33
import chalk from 'chalk'
44
import globby from 'globby'
5-
import { createResolver, APP_PATH } from './resolver'
5+
import { createResolver, APP_PATH, DEFAULT_THEME_PATH } from './resolver'
66
import { Resolver } from 'vite'
77
import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared'
88
import { MarkdownOptions } from './markdown/markdown'
@@ -48,7 +48,7 @@ export async function resolveConfig(
4848
const userThemeDir = resolve(root, 'theme')
4949
const themeDir = (await fs.pathExists(userThemeDir))
5050
? userThemeDir
51-
: path.join(__dirname, '../client/theme-default')
51+
: DEFAULT_THEME_PATH
5252

5353
const config: SiteConfig = {
5454
root,

src/node/resolver.ts

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { UserConfig } from './config'
44

55
export const APP_PATH = path.join(__dirname, '../client/app')
66
export const SHARED_PATH = path.join(__dirname, '../client/shared')
7+
export const DEFAULT_THEME_PATH = path.join(
8+
__dirname,
9+
'../client/theme-default'
10+
)
711

812
// special virtual file
913
// we can't directly import '/@siteData' becase
@@ -25,6 +29,7 @@ export function createResolver(
2529
...userConfig.alias,
2630
'/@app/': APP_PATH,
2731
'/@theme/': themeDir,
32+
'/@default-theme/': DEFAULT_THEME_PATH,
2833
'/@shared/': SHARED_PATH,
2934
vitepress: '/@app/exports.js',
3035
[SITE_DATA_ID]: SITE_DATA_REQUEST_PATH

types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './shared'
22
export * from '../dist/node/index'
33
export * from '../dist/client/app/exports'
44
export * from '../dist/client/theme-default/config'
5+
export { default as defaultTheme } from '../dist/client/theme-default/index'

0 commit comments

Comments
 (0)