Skip to content

Commit 020d376

Browse files
committed
docs: add theme-api reference
1 parent a9647c9 commit 020d376

File tree

4 files changed

+196
-4
lines changed

4 files changed

+196
-4
lines changed

docs/reference/plugin-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The following hooks will be processed in dev / build:
3737

3838
It will be used for identifying plugins to avoid using a same plugin multiple times, so make sure to use a unique plugin name.
3939

40-
It is recommended to use following format:
40+
It should follow the naming convention:
4141

4242
- Non-scoped: `vuepress-plugin-foo`
4343
- Scoped: `@org/vuepress-plugin-foo`

docs/reference/theme-api.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,99 @@
11
# Theme API
22

3-
> TODO
3+
VuePress theme also works as a plugin, so Theme API can accept all the options of [Plugin API](./plugin-api.md) with following differences.
4+
5+
## Basic Options
6+
7+
### name
8+
9+
- Type: `string`
10+
11+
- Details:
12+
13+
Name of the theme.
14+
15+
It should follow the naming convention:
16+
17+
- Non-scoped: `vuepress-theme-foo`
18+
- Scoped: `@org/vuepress-theme-foo`
19+
20+
### multiple
21+
22+
- Details:
23+
24+
A theme should never be used multiple times, so this option should not be set.
25+
26+
## Theme Specific Options
27+
28+
### layouts
29+
30+
- Type: `string | Record<string, string>`
31+
32+
- Details:
33+
34+
Specify layout components of the theme.
35+
36+
It accepts absolute path of the layouts directory. All the `.vue,.ts,.js` files in the directory will be registered as layout components.
37+
38+
It also accepts a plain object, of which the key is the layout name and the value is the absolute path of the layout file.
39+
40+
A theme must have at least two layouts: `Layout` and `NotFound`.
41+
42+
- Example:
43+
44+
The layout directory:
45+
46+
```bash
47+
layouts
48+
├─ Layout.vue
49+
├─ NotFound.vue
50+
└─ FooBar.vue
51+
```
52+
53+
Using the absolute path of layout directory:
54+
55+
```js
56+
module.exports = {
57+
layouts: path.resolve(__dirname, 'path/to/layouts'),
58+
}
59+
```
60+
61+
Using a plain object is equivalent:
62+
63+
```js
64+
module.exports = {
65+
layouts: {
66+
Layout: path.resolve(__dirname, 'path/to/layouts/Layout.vue'),
67+
NotFound: path.resolve(__dirname, 'path/to/layouts/NotFound.vue'),
68+
FooBar: path.resolve(__dirname, 'path/to/layouts/FooBar.vue'),
69+
},
70+
}
71+
```
72+
73+
### extends
74+
75+
- Type: `string`
76+
77+
- Details:
78+
79+
The name of the theme to inherit.
80+
81+
All of the Theme API of the parent theme will be inherited, but the child theme will not override the parent theme.
82+
83+
If a layout with the same name is registered in both the child theme and the parent theme, the layout of the child theme will have a higher priority.
84+
85+
Multi-level inheritance is not supported.
86+
87+
- Example:
88+
89+
```js
90+
module.exports = {
91+
// inherit the default theme
92+
extends: '@vuepress/theme-default',
93+
94+
// override the `NotFound` layout
95+
layouts: {
96+
NotFound: path.resolve(__dirname, 'path/to/NotFound.vue'),
97+
},
98+
}
99+
```

docs/zh/reference/plugin-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
它会被用来识别插件,以避免多次使用同一个插件,因此应确保你的插件名称是独一无二的。
3939

40-
建议使用以下命名格式
40+
它应遵从如下命名约定
4141

4242
- 非 Scoped: `vuepress-plugin-foo`
4343
- Scoped: `@org/vuepress-plugin-foo`

docs/zh/reference/theme-api.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,99 @@
11
# 主题 API
22

3-
> TODO
3+
VuePress 主题同样是一个插件,因此主题 API 可以接收 [插件 API](./plugin-api.md) 的所有选项,但存在以下差别:
4+
5+
## 基础配置项
6+
7+
### name
8+
9+
- 类型: `string`
10+
11+
- 详情:
12+
13+
主题的名称。
14+
15+
它应遵从如下命名约定:
16+
17+
- 非 Scoped: `vuepress-theme-foo`
18+
- Scoped: `@org/vuepress-theme-foo`
19+
20+
### multiple
21+
22+
- 详情:
23+
24+
主题永远不能被多次使用,因此不应设置该配置项。
25+
26+
## 主题特定配置项
27+
28+
### layouts
29+
30+
- 类型: `string | Record<string, string>`
31+
32+
- 详情:
33+
34+
指定主题的布局组件。
35+
36+
它可以接收布局目录的绝对路径。该目录下的所有 `.vue,.ts,.js` 文件都会被注册为布局组件。
37+
38+
它还可以接收一个普通对象,其键是布局名称,值是布局文件的绝对路径。
39+
40+
一个主题必须至少有两个布局: `Layout``NotFound`
41+
42+
- 示例:
43+
44+
布局目录:
45+
46+
```bash
47+
layouts
48+
├─ Layout.vue
49+
├─ NotFound.vue
50+
└─ FooBar.vue
51+
```
52+
53+
使用布局目录的绝对路径:
54+
55+
```js
56+
module.exports = {
57+
layouts: path.resolve(__dirname, 'path/to/layouts'),
58+
}
59+
```
60+
61+
使用普通对象是等效的:
62+
63+
```js
64+
module.exports = {
65+
layouts: {
66+
Layout: path.resolve(__dirname, 'path/to/layouts/Layout.vue'),
67+
NotFound: path.resolve(__dirname, 'path/to/layouts/NotFound.vue'),
68+
FooBar: path.resolve(__dirname, 'path/to/layouts/FooBar.vue'),
69+
},
70+
}
71+
```
72+
73+
### extends
74+
75+
- 类型: `string`
76+
77+
- 详情:
78+
79+
要继承的主题名称。
80+
81+
父主题的所有主题 API 都会被继承,但是子主题不会覆盖父主题。
82+
83+
如果在子主题和父主题中都注册了具有相同名称的布局,则子主题的布局将具有更高的优先级。
84+
85+
不支持多级继承。
86+
87+
- 示例:
88+
89+
```js
90+
module.exports = {
91+
// 继承默认主题
92+
extends: '@vuepress/theme-default',
93+
94+
// 覆盖 `NotFound` 布局
95+
layouts: {
96+
NotFound: path.resolve(__dirname, 'path/to/NotFound.vue'),
97+
},
98+
}
99+
```

0 commit comments

Comments
 (0)