默认主题

OnePress 自带了一个默认主题(就是你现在看到的这个),很多样式参考了 VuePress。

string

配置文档站的图标。

title

string,默认为 OnePress

配置文档站的标题,会显示在导航栏上,也会设置为 html 的 <title> 标签,即:

html
1<html>
2 <head>
3 <title>{YOUR_TITLE}</title>
4 </head>
5</html>

description

string

配置文档站的描述,会设置为 html 的 description meta ,即:

html
1<html>
2 <head>
3 <meta name="description" content="{YOUR_DESCRIPTION}" />
4 </head>
5</html>

类型:

ts
1type HeadConfig =
2 | [string, Record<string, string>]
3 | [string, Record<string, string>, string];
4
5head?: HeadConfig[];

可以通过该字段更大程度地配置 <head> 内容,例如:

js
1export default {
2 themeConfig: {
3 head: [
4 ['meta', { name: 'keywords', content: 'vite,react' }],
5 ['link', { rel: 'icon', href: '/logo.png' }],
6 ['script', {}, 'document.write("Hello World")'],
7 ],
8 },
9};

类型:

ts
1interface NavItem {
2 [key: string]: any;
3 text: string;
4 link?: string;
5 items?: NavItem[];
6}
7
8nav?: NavItem[];

配置顶部导航栏。例如:

js
1export default {
2 themeConfig: {
3 nav: [
4 {
5 text: '指南',
6 link: '/zh/guide',
7 },
8 ],
9 },
10};

类型:

ts
1interface SidebarItem {
2 [key: string]: any;
3 text: string;
4 link?: string;
5 items?: SidebarItem[];
6}
7
8sidebar?: SidebarItem[] | Record<string, SidebarItem[]>;

配置左侧菜单栏,例如:

js
1export default {
2 themeConfig: {
3 sidebar: [
4 {
5 text: '快速上手',
6 link: '/zh/guide/getting-started',
7 },
8 ],
9 },
10};

如果需要多个不同的左侧菜单栏,可以修改 sidebar 为以路径作为 key,SidebarItem[] 作为 value 的形式。 下面的例子就是,当进入 /foo/a 页面时会展示 /foo 菜单栏,而当进入 /bar/a 时则会展示 /bar 菜单栏:

js
1export default {
2 themeConfig: {
3 sidebar: {
4 '/foo': [
5 {
6 text: '关于 foo 的 a',
7 link: '/foo/a',
8 },
9 {
10 text: '关于 foo 的 b',
11 link: '/foo/b',
12 },
13 ],
14 '/bar': [
15 {
16 text: '关于 bar 的 a',
17 link: '/bar/a',
18 },
19 {
20 text: '关于 bar 的 b',
21 link: '/bar/b',
22 },
23 ],
24 },
25 },
26};

repo

string

配置 git 地址,如 https://github.com/Codpoe/onepress。 如果是 GitHub 仓库,那这个字段还可以简写为 Codpoe/onepress,OnePress 会自动补全链接。

当配置了仓库地址后,顶部导航栏会自动增加该 git 仓库地址的导航项。

repoText

string,默认 GitHub

docsRepo

string,默认同 repo 字段。

如果你的文档 git 地址跟项目的不一样,可以通过 docsRepo 字段单独指定文档 git 仓库地址。 该字段会用于拼接文档编辑按钮的链接。

docsDir

string,默认 /

文档目录。该字段会用于拼接文档编辑按钮的链接。

docsBranch

string,默认 master

文档分支。该字段会用于拼接文档编辑按钮的链接。

boolean | string,默认 false

是否在文档底部展示编辑按钮。

  • 当传递 true 时,编辑按钮的文字默认为 Edit this page
  • 当传递 string 时,会作为编辑按钮的文字来展示。

lastUpdated

boolean | string,默认 false

是否在文档底部展示上次更新的时间。

  • 当传递 true 时,上次更新时间的前缀文字默认为 Last updated
  • 当传递 string 时,会作为上次更新时间的前缀文字来展示。

algolia

WIP

配置 Algolia 的 DocSearch 服务。

locale

string

配置站点的语言,会被设置到 <html>lang 属性上。

当配置了语言后,顶部导航栏会自动增加语言切换的功能。

localeText

string,默认同 locale

配置站点语言对应的文案,用于顶部导航栏的语言切换。

themeConfigByPaths

Record<string, ThemeConfig>

不同的前置路径使用不同的主题配置。可用于配置多语言、多版本等场景。例如:

js
1export default {
2 themeConfig: {
3 locale: 'en',
4 localeText: 'English',
5 themeConfigByPaths: {
6 '/zh': {
7 locale: 'zh',
8 localeText: '中文',
9 },
10 },
11 },
12};

如上配置,默认情况下语言会是 English,而当进入 /zh/xxx 页面后,语言会变为 中文