You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/docs/theme/writing-a-theme.md
+17-24
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,22 @@ To write a theme, create a `.vuepress/theme` directory in your docs root, and th
11
11
12
12
From there it's the same as developing a normal Vue application. It is entirely up to you how to organize your theme.
13
13
14
+
## Content Outlet
15
+
16
+
The compiled content of the current `.md` file being rendered will be available as a special `<Content/>` global component. You will need to render it somewhere in your layout in order to display the content of the page. The simplest theme can be just a single `Layout.vue` component with the following content:
17
+
18
+
```html
19
+
<template>
20
+
<divclass="theme-container">
21
+
<Content/>
22
+
</div>
23
+
</template>
24
+
```
25
+
26
+
**Also see:**
27
+
28
+
-[Markdown Slot](../guide/markdown-slot.md)
29
+
14
30
## Directory Structure
15
31
16
32
Just one `Layout.vue` might not be enough, and you might also want to define more layout components in the theme for using on different pages. You may also want to customize the [palette](../config/README.md#palette), and even apply some plugins.
@@ -46,8 +62,7 @@ themePath
46
62
-`theme/enhanceApp.js`: Theme level enhancements.
47
63
48
64
::: warning Note
49
-
1. Considering backward compatibility, Vue components located at [themePath](../miscellaneous/glossary.md#theme-side) will also be automatically registered as layout components. But the recommended is placing them under `themePath/layouts` directory, which looks more clearer.
50
-
2. When you want to publish your theme as an npm package, make sure the package has `index.js`, and set `"main"` field at `package.json` to `index.js` so that VuePress can resolve and get the correct [themePath](../miscellaneous/glossary.md#theme-side).
65
+
When you want to publish your theme as an npm package, make sure the package has `index.js`, and set `"main"` field at `package.json` to `index.js` so that VuePress can resolve and get the correct [themePath](../miscellaneous/glossary.md#theme-side).
51
66
52
67
```json
53
68
{
@@ -97,16 +112,6 @@ module.exports = {
97
112
}
98
113
```
99
114
100
-
For themes that need to be released to NPM, please do not forget to add it to `dependencies`:
101
-
102
-
```json
103
-
{
104
-
"dependencies": {
105
-
"@vuepress/plugin-pwa": "^x.x.x",
106
-
}
107
-
}
108
-
```
109
-
110
115
## Site and Page Metadata
111
116
112
117
The `Layout` component will be invoked once for every `.md` file in `docs`, and the metadata for the entire site and that specific page will be exposed respectively as `this.$site` and `this.$page` properties which are injected into every component in the app.
@@ -156,18 +161,6 @@ Finally, don't forget that `this.$route` and `this.$router` are also available a
156
161
157
162
If a markdown file contains a `<!-- more -->` comment, any content above the comment will be extracted and exposed as `$page.excerpt`. If you are building custom theme for blogging, this data can be used to render a post list with excerpts.
158
163
159
-
## Content Outlet
160
-
161
-
The compiled content of the current `.md` file being rendered will be available as a special `<Content/>` global component. You will need to render it somewhere in your layout in order to display the content of the page. The simplest theme can be just a single `Layout.vue` component with the following content:
162
-
163
-
```html
164
-
<template>
165
-
<divclass="theme-container">
166
-
<Content/>
167
-
</div>
168
-
</template>
169
-
```
170
-
171
164
## App Level Enhancements
172
165
173
166
Themes can enhance the Vue app that VuePress uses by exposing an `enhanceApp.js` file at the root of the theme. The file should `export default` a hook function which will receive an object containing some app level values. You can use this hook to install additional Vue plugins, register global components, or add additional router hooks:
0 commit comments