mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
413 lines
9.8 KiB
413 lines
9.8 KiB
2 years ago
|
# App Config
|
||
3 years ago
|
|
||
2 years ago
|
App config is where you can define the global settings of the site. App config options define settings that apply to every VitePress site, regardless of what theme it is using. For example, the base directory or the title of the site.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
// app level config options
|
||
3 years ago
|
lang: 'en-US',
|
||
|
title: 'VitePress',
|
||
|
description: 'Vite & Vue powered static site generator.',
|
||
|
...
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## appearance
|
||
|
|
||
2 years ago
|
- Type: `boolean | 'dark'`
|
||
2 years ago
|
- Default: `true`
|
||
|
|
||
2 years ago
|
Whether to enable dark mode or not.
|
||
|
|
||
|
- If the option is set to `true`, the default theme will be determined by the user's preferred color scheme.
|
||
|
- If the option is set to `dark`, the theme will be dark by default, unless the user manually toggles it.
|
||
|
- If the option is set to `false`, users will not be able to toggle the theme.
|
||
2 years ago
|
|
||
|
It also injects inline script that tries to read users settings from local storage by `vitepress-theme-appearance` key and restores users preferred color mode.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
appearance: true
|
||
|
}
|
||
|
```
|
||
|
|
||
3 years ago
|
## base
|
||
|
|
||
|
- Type: `string`
|
||
|
- Default: `/`
|
||
|
|
||
|
The base URL the site will be deployed at. You will need to set this if you plan to deploy your site under a sub path, for example, GitHub pages. If you plan to deploy your site to `https://foo.github.io/bar/`, then you should set base to `'/bar/'`. It should always start and end with a slash.
|
||
|
|
||
|
The base is automatically prepended to all the URLs that start with / in other options, so you only need to specify it once.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
base: '/base/'
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## description
|
||
3 years ago
|
|
||
|
- Type: `string`
|
||
2 years ago
|
- Default: `A VitePress site`
|
||
3 years ago
|
|
||
2 years ago
|
Description for the site. This will render as a `<meta>` tag in the page HTML.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
description: 'A VitePress site'
|
||
3 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## head
|
||
|
|
||
|
- Type: `HeadConfig[]`
|
||
|
- Default: `[]`
|
||
|
|
||
|
Additional elements to render in the `<head>` tag in the page HTML. The user-added tags are rendered before the closing `head` tag, after VitePress tags.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
head: [
|
||
2 years ago
|
[
|
||
|
'link',
|
||
|
{ rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '' }
|
||
|
]
|
||
2 years ago
|
// would render: <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||
|
]
|
||
|
}
|
||
|
```
|
||
|
|
||
|
```ts
|
||
|
type HeadConfig =
|
||
|
| [string, Record<string, string>]
|
||
|
| [string, Record<string, string>, string]
|
||
|
```
|
||
|
|
||
2 years ago
|
## ignoreDeadLinks
|
||
3 years ago
|
|
||
2 years ago
|
- Type: `boolean | 'localhostLinks'`
|
||
2 years ago
|
- Default: `false`
|
||
3 years ago
|
|
||
2 years ago
|
When set to `true`, VitePress will not fail builds due to dead links. When set to `localhostLinks`, the build will fail on dead links, but won't check `localhost` links.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
ignoreDeadLinks: true
|
||
3 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## lang
|
||
3 years ago
|
|
||
2 years ago
|
- Type: `string`
|
||
|
- Default: `en-US`
|
||
3 years ago
|
|
||
2 years ago
|
The lang attribute for the site. This will render as a `<html lang="en-US">` tag in the page HTML.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
lang: 'en-US'
|
||
3 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## lastUpdated
|
||
3 years ago
|
|
||
2 years ago
|
- Type: `boolean`
|
||
|
- Default: `false`
|
||
3 years ago
|
|
||
2 years ago
|
Use git commit to get the timestamp. This option enables the default theme to display the page's last updated time. You can customize the text via [`themeConfig.lastUpdatedText`](theme-config#lastupdatedtext) option.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
lastUpdated: true
|
||
3 years ago
|
}
|
||
|
```
|
||
|
|
||
3 years ago
|
## markdown
|
||
|
|
||
|
- Type: `MarkdownOption`
|
||
|
|
||
2 years ago
|
Configure Markdown parser options. VitePress uses [Markdown-it](https://github.com/markdown-it/markdown-it) as the parser, and [Shiki](https://shiki.matsu.io/) to highlight language syntax. Inside this option, you may pass various Markdown related options to fit your needs.
|
||
3 years ago
|
|
||
|
```js
|
||
|
export default {
|
||
|
markdown: {
|
||
2 years ago
|
theme: 'material-theme-palenight',
|
||
3 years ago
|
lineNumbers: true
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
Below are all the options that you can have in this object:
|
||
3 years ago
|
|
||
|
```ts
|
||
|
interface MarkdownOptions extends MarkdownIt.Options {
|
||
2 years ago
|
// Custom theme for syntax highlighting.
|
||
|
// You can use an existing theme.
|
||
3 years ago
|
// See: https://github.com/shikijs/shiki/blob/main/docs/themes.md#all-themes
|
||
2 years ago
|
// Or add your own theme.
|
||
|
// See: https://github.com/shikijs/shiki/blob/main/docs/themes.md#loading-theme
|
||
|
theme?:
|
||
|
| Shiki.IThemeRegistration
|
||
|
| { light: Shiki.IThemeRegistration; dark: Shiki.IThemeRegistration }
|
||
3 years ago
|
|
||
|
// Enable line numbers in code block.
|
||
|
lineNumbers?: boolean
|
||
|
|
||
|
// markdown-it-anchor plugin options.
|
||
2 years ago
|
// See: https://github.com/valeriangalliat/markdown-it-anchor#usage
|
||
|
anchor?: anchorPlugin.AnchorOptions
|
||
3 years ago
|
|
||
|
// markdown-it-attrs plugin options.
|
||
|
// See: https://github.com/arve0/markdown-it-attrs
|
||
|
attrs?: {
|
||
|
leftDelimiter?: string
|
||
|
rightDelimiter?: string
|
||
|
allowedAttributes?: string[]
|
||
3 years ago
|
disable?: boolean
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
// specify default language for syntax highlighter
|
||
|
defaultHighlightLang?: string
|
||
|
|
||
2 years ago
|
// @mdit-vue/plugin-frontmatter plugin options.
|
||
|
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-frontmatter#options
|
||
|
frontmatter?: FrontmatterPluginOptions
|
||
|
|
||
|
// @mdit-vue/plugin-headers plugin options.
|
||
|
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-headers#options
|
||
|
headers?: HeadersPluginOptions
|
||
|
|
||
|
// @mdit-vue/plugin-sfc plugin options.
|
||
|
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-sfc#options
|
||
|
sfc?: SfcPluginOptions
|
||
|
|
||
2 years ago
|
// @mdit-vue/plugin-toc plugin options.
|
||
|
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
|
||
|
toc?: TocPluginOptions
|
||
3 years ago
|
|
||
2 years ago
|
// Configure the Markdown-it instance.
|
||
3 years ago
|
config?: (md: MarkdownIt) => void
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## outDir
|
||
|
|
||
|
- Type: `string`
|
||
|
- Default: `./.vitepress/dist`
|
||
|
|
||
|
The build output location for the site, relative to project root (`docs` folder if you're running `vitepress build docs`).
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
outDir: '../public'
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## cacheDir
|
||
|
|
||
|
- Type: `string`
|
||
|
- Default: `./.vitepress/cache`
|
||
|
|
||
|
The directory for cache files, relative to project root (`docs` folder if you're running `vitepress build docs`). See also: [cacheDir](https://vitejs.dev/config/shared-options.html#cachedir).
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
cacheDir: './.vitepress/.vite'
|
||
2 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## srcDir
|
||
|
|
||
|
- Type: `string`
|
||
|
- Default: `.`
|
||
|
|
||
2 years ago
|
The directory where your markdown pages are stored, relative to project root.
|
||
2 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
|
srcDir: './src'
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## title
|
||
3 years ago
|
|
||
2 years ago
|
- Type: `string`
|
||
|
- Default: `VitePress`
|
||
3 years ago
|
|
||
2 years ago
|
Title for the site. This will be displayed in the nav bar. Also used as the suffix for all page titles unless `titleTemplate` is defined.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
title: 'VitePress'
|
||
3 years ago
|
}
|
||
|
```
|
||
3 years ago
|
|
||
2 years ago
|
## titleTemplate
|
||
3 years ago
|
|
||
2 years ago
|
- Type: `string | boolean`
|
||
3 years ago
|
|
||
2 years ago
|
The suffix for the title. For example, if you set `title` as `VitePress` and set `titleTemplate` as `My Site`, the html title becomes `VitePress | My Site`.
|
||
|
|
||
|
Set `false` to disable the feature. If the option is `undefined`, then the value of `title` option will be used.
|
||
3 years ago
|
|
||
|
```ts
|
||
|
export default {
|
||
2 years ago
|
title: 'VitePress',
|
||
|
titleTemplate: 'Vite & Vue powered static site generator'
|
||
3 years ago
|
}
|
||
|
```
|
||
2 years ago
|
|
||
2 years ago
|
To configure a title separator other than `|`, you can omit `title` and use the `:title` symbol in `titleTemplate`.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
titleTemplate: ':title - Vitepress'
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
## cleanUrls
|
||
2 years ago
|
|
||
2 years ago
|
- Type: `boolean`
|
||
|
- Default: `false`
|
||
2 years ago
|
|
||
2 years ago
|
Allows removing trailing `.html` from URLs.
|
||
2 years ago
|
|
||
2 years ago
|
```ts
|
||
|
export default {
|
||
2 years ago
|
cleanUrls: true
|
||
2 years ago
|
}
|
||
|
```
|
||
2 years ago
|
|
||
2 years ago
|
::: warning
|
||
2 years ago
|
Enabling this may require additional configuration on your hosting platform. For it to work, your server must serve `/foo.html` on requesting `/foo` **without a redirect**.
|
||
2 years ago
|
:::
|
||
|
|
||
2 years ago
|
## rewrites
|
||
|
|
||
|
- Type: `Record<string, string>`
|
||
|
|
||
|
Defines custom directory <-> URL mappings. See [Routing: Customize the Mappings](/guide/routing#customize-the-mappings) for more details.
|
||
|
|
||
2 years ago
|
```ts
|
||
|
export default {
|
||
2 years ago
|
rewrites: {
|
||
|
'source/:page': 'destination/:page'
|
||
|
}
|
||
2 years ago
|
}
|
||
|
```
|
||
2 years ago
|
|
||
|
## Build Hooks
|
||
|
|
||
|
VitePress build hooks allow you to add new functionality and behaviors to your website:
|
||
|
|
||
|
- Sitemap
|
||
|
- Search Indexing
|
||
|
- PWA
|
||
2 years ago
|
- Teleports
|
||
|
|
||
|
### buildEnd
|
||
|
|
||
|
- Type: `(siteConfig: SiteConfig) => Awaitable<void>`
|
||
|
|
||
|
`buildEnd` is a build CLI hook, it will run after build (SSG) finish but before VitePress CLI process exits.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
async buildEnd(siteConfig) {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### postRender
|
||
|
|
||
|
- Type: `(context: SSGContext) => Awaitable<SSGContext | void>`
|
||
|
|
||
|
`postRender` is a build hook, called when SSG rendering is done. It will allow you to handle the teleports content during SSG.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
async postRender(context) {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
```ts
|
||
|
interface SSGContext {
|
||
|
content: string
|
||
|
teleports?: Record<string, string>
|
||
|
[key: string]: any
|
||
|
}
|
||
|
```
|
||
2 years ago
|
|
||
2 years ago
|
### transformHead
|
||
2 years ago
|
|
||
2 years ago
|
- Type: `(context: TransformContext) => Awaitable<HeadConfig[]>`
|
||
2 years ago
|
|
||
2 years ago
|
`transformHead` is a build hook to transform the head before generating each page. It will allow you to add head entries that cannot be statically added to your VitePress config. You only need to return extra entries, they will be merged automatically with the existing ones.
|
||
2 years ago
|
|
||
|
::: warning
|
||
2 years ago
|
Don't mutate anything inside the `ctx`.
|
||
2 years ago
|
:::
|
||
|
|
||
|
```ts
|
||
2 years ago
|
export default {
|
||
2 years ago
|
async transformHead(context) {
|
||
2 years ago
|
// ...
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
```
|
||
|
|
||
|
```ts
|
||
|
interface TransformContext {
|
||
|
siteConfig: SiteConfig
|
||
|
siteData: SiteData
|
||
|
pageData: PageData
|
||
|
title: string
|
||
|
description: string
|
||
|
head: HeadConfig[]
|
||
|
content: string
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
### transformHtml
|
||
|
|
||
|
- Type: `(code: string, id: string, ctx: TransformContext) => Awaitable<string | void>`
|
||
|
|
||
|
`transformHtml` is a build hook to transform the content of each page before saving to disk.
|
||
|
|
||
|
::: warning
|
||
|
Don't mutate anything inside the `ctx`. Also, modifying the html content may cause hydration problems in runtime.
|
||
|
:::
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
async transformHtml(code, id, context) {
|
||
2 years ago
|
// ...
|
||
2 years ago
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
### transformPageData
|
||
|
|
||
|
- Type: `(pageData: PageData) => Awaitable<Partial<PageData> | { [key: string]: any } | void>`
|
||
|
|
||
|
`transformPageData` is a hook to transform the `pageData` of each page. You can directly mutate `pageData` or return changed values which will be merged into PageData.
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
async transformPageData(pageData) {
|
||
|
pageData.contributors = await getPageContributors(pageData.relativePath)
|
||
|
}
|
||
|
|
||
|
// or return data to be merged
|
||
|
async transformPageData(pageData) {
|
||
|
return {
|
||
|
contributors: await getPageContributors(pageData.relativePath)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|