Skip to content

Commit f4a5c43

Browse files
committedAug 6, 2023
feat(theme): allow adding custom layouts
closes #2547
1 parent a8cf88b commit f4a5c43

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎docs/reference/default-theme-layout.md

+24
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,27 @@ Option `home` will generate templated "Homepage". In this layout, you can set ex
3636
## No Layout
3737

3838
If you don't want any layout, you can pass `layout: false` through frontmatter. This option is helpful if you want a fully-customizable landing page (without any sidebar, navbar, or footer by default).
39+
40+
## Custom Layout
41+
42+
You can also use a custom layout:
43+
44+
```md
45+
---
46+
layout: foo
47+
---
48+
```
49+
50+
This will look for a component named `foo` registered in context. For example, you can register your component globally in `.vitepress/theme/index.ts`:
51+
52+
```ts
53+
import DefaultTheme from 'vitepress/theme'
54+
import Foo from './Foo.vue'
55+
56+
export default {
57+
extends: DefaultTheme,
58+
enhanceApp({ app }) {
59+
app.component('foo', Foo)
60+
}
61+
}
62+
```

‎src/client/theme-default/components/VPContent.vue

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const { hasSidebar } = useSidebar()
3535
<template #home-features-after><slot name="home-features-after" /></template>
3636
</VPHome>
3737

38+
<component
39+
v-else-if="frontmatter.layout && frontmatter.layout !== 'doc'"
40+
:is="frontmatter.layout"
41+
/>
42+
3843
<VPDoc v-else>
3944
<template #doc-top><slot name="doc-top" /></template>
4045
<template #doc-bottom><slot name="doc-bottom" /></template>

0 commit comments

Comments
 (0)
Please sign in to comment.