Skip to content

Commit

Permalink
feat(theme): allow adding custom layouts
Browse files Browse the repository at this point in the history
closes #2547
  • Loading branch information
brc-dd committed Aug 6, 2023
1 parent a8cf88b commit f4a5c43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/reference/default-theme-layout.md
Expand Up @@ -36,3 +36,27 @@ Option `home` will generate templated "Homepage". In this layout, you can set ex
## No Layout

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).

## Custom Layout

You can also use a custom layout:

```md
---
layout: foo
---
```

This will look for a component named `foo` registered in context. For example, you can register your component globally in `.vitepress/theme/index.ts`:

```ts
import DefaultTheme from 'vitepress/theme'
import Foo from './Foo.vue'

export default {
extends: DefaultTheme,
enhanceApp({ app }) {
app.component('foo', Foo)
}
}
```
5 changes: 5 additions & 0 deletions src/client/theme-default/components/VPContent.vue
Expand Up @@ -35,6 +35,11 @@ const { hasSidebar } = useSidebar()
<template #home-features-after><slot name="home-features-after" /></template>
</VPHome>

<component
v-else-if="frontmatter.layout && frontmatter.layout !== 'doc'"
:is="frontmatter.layout"
/>

<VPDoc v-else>
<template #doc-top><slot name="doc-top" /></template>
<template #doc-bottom><slot name="doc-bottom" /></template>
Expand Down

0 comments on commit f4a5c43

Please sign in to comment.