主 题配置
This configuration applies to all main themes.
通用
色彩模式
经典主题默认提供浅色主题和暗黑主题,用户可以通过导航栏切换。
可以通过 colorMode
对象自定义色彩模式支持。
接受的字段:
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
defaultMode | 'light' | 'dark' | 'light' | 用户首次访问网站时的色彩模式。 |
disableSwitch | boolean | false | 在导航栏隐藏按钮。 如果你想要只支持一种色彩模式很有用。 |
respectPrefersColorScheme | boolean | false | 是否使用 prefers-color-scheme 媒体查询,从而使用用户系统的首选项,而不是硬代码的 defaultMode 。 |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
colorMode: {
defaultMode: 'light',
disableSwitch: false,
respectPrefersColorScheme: false,
},
},
};
警告
如果使用 respectPrefersColorScheme: true
,defaultMode
会被用户系统的偏好设置覆盖。
如果你只想支持一种色彩模式,你大概率会想要忽略用户系统的偏好设置。
元数据图像
你可以配置用于元标签的默认图像,尤其是 og:image
和 twitter:image
。
接受的字段:
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
image | string | undefined | 网站的元数据图像 URL。 相对于你的网站的静态目录。 不能是 SVG。 可以是外部链接。 |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
image: 'img/docusaurus.png',
},
};
元数据
你可以配置额外的 HTML 元数据(以及覆盖现有数据)。
接受的字段:
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
metadata | Metadata[] | [] | 所有字段都会被直接传递给 <meta /> 标签。 可选的字段包括 id 、name 、property 、content 、itemprop 等。 |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
metadata: [{name: 'twitter:card', content: 'summary'}],
},
};
告示条
有时候,你需要在网站上发布告示。 这种情况下,你可以添加一个告示条。 这是位于导航栏上方的一个面板,非固定而且可以关闭。 所有配置都在 announcementBar
对象中。
接受的字段:
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
id | string | 'announcement-bar' | 任何能够唯一标识此信息的值。 |
content | string | '' | 告示的文字内容。 HTML 也可以识别。 |
backgroundColor | string | '#fff' | 告示条的背景颜色。 |
textColor | string | '#000' | 告示的文字颜色。 |
isCloseable | boolean | true | 是否可以用 '×' 按钮关闭告示。 |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
announcementBar: {
id: 'support_us',
content:
'We are looking to revamp our docs, please fill <a target="_blank" rel="noopener noreferrer" href="#">this survey</a>',
backgroundColor: '#fafbfc',
textColor: '#091E42',
isCloseable: false,
},
},
};
插件
Our main themes offer additional theme configuration options for Docusaurus core content plugins.
文档
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
versionPersistence | 'localStorage' | 'none' | undefined | Defines the browser persistence of the preferred docs version. |
sidebar.hideable | boolean | false | Show a hide button at the bottom of the sidebar. |
sidebar.autoCollapseCategories | boolean | false | Automatically collapse all sibling categories of the one you navigate to. |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
docs: {
versionPersistence: 'localStorage',
sidebar: {
hideable: false,
autoCollapseCategories: false,
},
},
},
};
博客
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
sidebar.groupByYear | boolean | true | Group sidebar blog posts by years. |
示例配置:
docusaurus.config.js
export default {
themeConfig: {
blog: {
sidebar: {
groupByYear: true,
},
},
},
};