默认主题配置
主题配置允许您自定义主题。您可以通过配置文件中的themeConfig
选项定义主题配置:
export default {
lang: 'en-US',
title: 'VitePress',
description: 'Vite & Vue powered static site generator.',
// Theme related configurations.
themeConfig: {
logo: '/logo.svg',
nav: [...],
sidebar: { ... }
}
}
本页记录的选项仅适用于默认主题。不同的主题需要不同的主题配置。使用自定义主题时,主题配置对象将传递给主题,以便主题可以基于它定义条件行为。
i18nRouting
- 类型:
boolean
将语言环境更改为zh
会将 URL 从/foo
(或/en/foo/
)更改为/zh/foo
。您可以通过将themeConfig.i18nRouting
设置为false
来禁用此行为。
logo
- 类型:
ThemeableImage
显示在导航栏中网站标题之前的logo文件。接受路径字符串或对象来为亮/暗模式设置不同的logo。
export default {
themeConfig: {
logo: '/logo.svg'
}
}
type ThemeableImage =
| string
| { src: string; alt?: string }
| { light: string; dark: string; alt?: string }
siteTitle
- 类型:
string | false
您可以自定义此项以替换导航中的默认站点标题(应用程序配置中的title
)。当设置为false
时,导航中的标题将被禁用。当您的logo
已包含网站标题文本时很有用。
export default {
themeConfig: {
siteTitle: 'Hello World'
}
}
nav
- 类型:
NavItem
导航菜单项的配置。更多详细信息请参见默认主题:导航。
export default {
themeConfig: {
nav: [
{ text: 'Guide', link: '/guide' },
{
text: 'Dropdown Menu',
items: [
{ text: 'Item A', link: '/item-1' },
{ text: 'Item B', link: '/item-2' },
{ text: 'Item C', link: '/item-3' }
]
}
]
}
}
type NavItem = NavItemWithLink | NavItemWithChildren
interface NavItemWithLink {
text: string
link: string
activeMatch?: string
target?: string
rel?: string
}
interface NavItemChildren {
text?: string
items: NavItemWithLink[]
}
interface NavItemWithChildren {
text?: string
items: (NavItemChildren | NavItemWithLink)[]
activeMatch?: string
}
sidebar
- 类型:
Sidebar
侧边栏菜单项的配置。更多详细信息请参见默认主题:侧边栏。
export default {
themeConfig: {
sidebar: [
{
text: 'Guide',
items: [
{ text: 'Introduction', link: '/introduction' },
{ text: 'Getting Started', link: '/getting-started' },
...
]
}
]
}
}
export type Sidebar = SidebarItem[] | SidebarMulti
export interface SidebarMulti {
[path: string]: SidebarItem[]
}
export type SidebarItem = {
/**
* The text label of the item.
*/
text?: string
/**
* The link of the item.
*/
link?: string
/**
* The children of the item.
*/
items?: SidebarItem[]
/**
* If not specified, group is not collapsible.
*
* If `true`, group is collapsible and collapsed by default
*
* If `false`, group is collapsible but expanded by default
*/
collapsed?: boolean
}
aside
- 类型:
boolean | 'left'
- 默认值:
true
- 可以通过页面的frontmatter进行覆盖。
将此值设置为false
可防止渲染旁路容器。
将此值设置为true
会将旁边渲染到右侧。
将此值设置为left
会将一侧呈现在左侧。
outline
- 类型:
number | [number, number] | 'deep' | false
- 默认值:
2
- 可以通过页面的frontmatter进行覆盖。
在大纲中显示的标题级别。您可以通过传递数字来指定特定级别,也可以通过传递包含下限和上限的元组来提供级别范围。当传递等于[2, 6]
的'deep'
时,除h1
之外的所有标题级别都显示在大纲中。设置false
以隐藏轮廓。
outlineTitle
- 类型:
string
- 默认值:
On this page
可用于自定义右侧边栏的标题(位于大纲链接的顶部)。当用另一种语言编写文档时,这很有用。
export default {
themeConfig: {
outlineTitle: 'In hac pagina'
}
}
socialLinks
- 类型:
SocialLink[]
您可以定义此选项以在导航中显示带有图标的社交帐户链接。
export default {
themeConfig: {
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'twitter', link: '...' },
// You can also add custom icons by passing SVG as string:
{
icon: {
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
},
link: '...',
// You can include a custom label for accessibility too (optional but recommended):
ariaLabel: 'cool link'
}
]
}
}
interface SocialLink {
icon: SocialLinkIcon
link: string
ariaLabel?: string
}
type SocialLinkIcon =
| 'discord'
| 'facebook'
| 'github'
| 'instagram'
| 'linkedin'
| 'mastodon'
| 'slack'
| 'twitter'
| 'youtube'
| { svg: string }
footer
- 类型:
Footer
- 可以通过frontmatter在每个页面上进行覆盖。
页脚配置。您可以在页脚上添加消息或版权文本,但是,只有当页面不包含侧边栏时才会显示它。这是由于设计方面的考虑。
export default {
themeConfig: {
footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2019-present Evan You'
}
}
}
export interface Footer {
message?: string
copyright?: string
}
editLink
- 类型:
EditLink
- 可以通过页面的frontmatter进行覆盖。
编辑链接允许您显示用于编辑 Git 管理服务(例如 GitHub 或 GitLab)上的页面的链接。有关更多详细信息,请参阅默认主题:编辑链接。
export default {
themeConfig: {
editLink: {
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
text: 'Edit this page on GitHub'
}
}
}
export interface EditLink {
pattern: string
text?: string
}
lastUpdated
- 类型:
LastUpdatedOptions
允许自定义最后更新文本和日期格式。
export default {
themeConfig: {
lastUpdated: {
text: 'Updated at',
formatOptions: {
dateStyle: 'full',
timeStyle: 'medium'
}
}
}
}
export interface LastUpdatedOptions {
/**
* @default 'Last updated'
*/
text?: string
/**
* @default
* { dateStyle: 'short', timeStyle: 'short' }
*/
formatOptions?: Intl.DateTimeFormatOptions
}
algolia
- 类型:
AlgoliaSearch
支持使用 Algolia DocSearch 搜索文档网站的选项。了解更多信息默认主题:搜索
export interface AlgoliaSearchOptions extends DocSearchProps {
locales?: Record<string, Partial<DocSearchProps>>
}
查看完整选项此处。
carbonAds
- 类型:
CarbonAdsOptions
显示 Carbon 广告 的选项。
export default {
themeConfig: {
carbonAds: {
code: 'your-carbon-code',
placement: 'your-carbon-placement'
}
}
}
export interface CarbonAdsOptions {
code: string
placement: string
}
了解更多信息默认主题:Carbon 广告
docFooter
- 类型:
DocFooter
可用于自定义上一个和下一个链接上方显示的文本。如果不用英语编写文档,很有帮助。也可用于全局禁用上一个/下一个链接。如果您想有选择地启用/禁用上一个/下一个链接,可以使用 frontmatter。
export default {
themeConfig: {
docFooter: {
prev: 'Pagina prior',
next: 'Proxima pagina'
}
}
}
export interface DocFooter {
prev?: string | false
next?: string | false
}
darkModeSwitchLabel
- 类型:
string
- 默认值:
Appearance
可用于自定义深色模式开关标签。该标签仅显示在移动视图中。
sidebarMenuLabel
- 类型:
string
- 默认值:
Menu
可用于自定义侧边栏菜单标签。该标签仅显示在移动视图中。
returnToTopLabel
- 类型:
string
- 默认值:
Return to top
可用于自定义返回顶部按钮的标签。该标签仅显示在移动视图中。
langMenuLabel
- 类型:
string
- 默认值:
Change language
可用于自定义导航栏中语言切换按钮的 aria-label。仅当您使用 i18n 时才使用此选项。
externalLinkIcon
- 类型:
boolean
- 默认值:
false
是否在Markdown中的外部链接旁显示外部链接图标。