From 8a2ac4a1b0127cb99e7f714697b276ddef0dda13 Mon Sep 17 00:00:00 2001 From: Xavi Lee Date: Thu, 16 Mar 2023 10:41:07 +0800 Subject: [PATCH] sync --- docs/zh/guide/asset-handling.md | 16 ++- docs/zh/guide/cms.md | 2 +- docs/zh/guide/custom-theme.md | 8 +- docs/zh/guide/data-loading.md | 111 ++++++++++++++-- docs/zh/guide/deploy.md | 124 ++++++++++++------ docs/zh/guide/extending-default-theme.md | 80 ++++++++++- docs/zh/guide/frontmatter.md | 4 +- docs/zh/guide/getting-started.md | 12 +- docs/zh/guide/i18n.md | 2 +- docs/zh/guide/markdown.md | 8 +- docs/zh/guide/migration-from-vitepress-0.md | 8 +- docs/zh/guide/mpa-mode.md | 6 +- docs/zh/guide/routing.md | 30 +++-- docs/zh/guide/ssr-compat.md | 84 ++++++++++++ docs/zh/guide/using-vue.md | 73 ++--------- docs/zh/guide/what-is-vitepress.md | 6 +- docs/zh/reference/cli.md | 4 +- docs/zh/reference/default-theme-config.md | 12 +- docs/zh/reference/default-theme-edit-link.md | 32 +++++ docs/zh/reference/default-theme-footer.md | 2 +- .../reference/default-theme-last-updated.md | 11 +- docs/zh/reference/default-theme-layout.md | 4 +- docs/zh/reference/default-theme-nav.md | 6 +- docs/zh/reference/default-theme-sidebar.md | 2 +- docs/zh/reference/default-theme-team-page.md | 2 +- docs/zh/reference/frontmatter-config.md | 27 +++- docs/zh/reference/runtime-api.md | 10 +- docs/zh/reference/site-config.md | 72 ++++++---- 28 files changed, 544 insertions(+), 214 deletions(-) create mode 100644 docs/zh/guide/ssr-compat.md diff --git a/docs/zh/guide/asset-handling.md b/docs/zh/guide/asset-handling.md index c1f46675..c914bf31 100644 --- a/docs/zh/guide/asset-handling.md +++ b/docs/zh/guide/asset-handling.md @@ -1,5 +1,7 @@ # Asset Handling +## Referencing Static Assets + All Markdown files are compiled into Vue components and processed by [Vite](https://vitejs.dev/guide/assets.html). You can, **and should**, reference any assets using relative URLs: ```md @@ -10,19 +12,21 @@ You can reference static assets in your markdown files, your `*.vue` components Common image, media, and font filetypes are detected and included as assets automatically. -All referenced assets, including those using absolute paths, will be copied to the dist folder with a hashed file name in the production build. Never-referenced assets will not be copied. Image assets smaller than 4kb will be base64 inlined - this can be configured via the [`vite`](/reference/site-config#vite) config option. +All referenced assets, including those using absolute paths, will be copied to the output directory with a hashed file name in the production build. Never-referenced assets will not be copied. Image assets smaller than 4kb will be base64 inlined - this can be configured via the [`vite`](../reference/site-config#vite) config option. All **static** path references, including absolute paths, should be based on your working directory structure. -## Public Files +## The Public Directory + +Sometimes you may need to provide static assets that are not directly referenced in any of your Markdown or theme components, or you may want to serve certain files with the original filename. Examples of such files include `robot.txt`, favicons, and PWA icons. -Sometimes you may need to provide static assets that are not directly referenced in any of your Markdown or theme components (for example, favicons and PWA icons). The `public` directory under project root (`docs` folder if you're running `vitepress build docs`) can be used as an escape hatch to provide static assets that either are never referenced in source code (e.g. `robots.txt`), or must retain the exact same file name (without hashing). +You can place these files in the `public` directory under the [source directory](./routing#source-directory). For example, if your project root is `./docs` and using default source directory location, then your public directory will be `./docs/public`. -Assets placed in `public` will be copied to the root of the dist directory as-is. +Assets placed in `public` will be copied to the root of the output directory as-is. Note that you should reference files placed in `public` using root absolute path - for example, `public/icon.png` should always be referenced in source code as `/icon.png`. -There is one exception to this: if you have an HTML page in `public` and link to it from the main site, the router will yield a 404 by default. To get around this, VitePress provides a `pathname://` protocol which allows you to link to another page in the same domain as if the link is external. Contrast these two links: +There is one exception to this: if you have an HTML page in `public` and link to it from the main site, the router will yield a 404 by default. To get around this, VitePress provides a `pathname://` protocol which allows you to link to another page in the same domain as if the link is external. Compare these two links: - [/pure.html](/pure.html) - @@ -45,7 +49,7 @@ However, if you are authoring a theme component that links to assets dynamically ``` -In this case it is recommended to wrap the path with the [`withBase` helper](/reference/runtime-api#withbase) provided by VitePress: +In this case it is recommended to wrap the path with the [`withBase` helper](../reference/runtime-api#withbase) provided by VitePress: ```vue + + +``` + +### Options + +The default data may not suit all needs - you can opt-in to transform the data using options: + +```js +// posts.data.js +import { createContentLoader } from 'vitepress' + +export default createContentLoader('posts/*.md', { + includeSrc: true, // include raw markdown source? + render: true, // include rendered full page HTML? + excerpt: true, // include excerpt? + transform(rawData) { + // map, sort, or filter the raw data as you wish. + // the final result is what will be shipped to the client. + return rawData.sort((a, b) => { + return +new Date(b.frontmatter.date) - +new Date(a.frontmatter.date) + }).map(page => { + page.src // raw markdown source + page.html // rendered full page HTML + page.excerpt // rendered excerpt HTML (content above first `---`) + return {/* ... */} }) } +}) +``` + +Check out how it is used in the [Vue.js blog](https://github.com/vuejs/blog/blob/main/.vitepress/theme/posts.data.ts). + +The `createContentLoader` API can also be used inside [build hooks](/reference/site-config#build-hooks): + +```js +// .vitepress/config.js +export default { + async buildEnd() { + const posts = await createContentLoader('posts/*.md').load() + // generate files based on posts metadata, e.g. RSS feed + } } ``` diff --git a/docs/zh/guide/deploy.md b/docs/zh/guide/deploy.md index 904924c5..3bf9c3ea 100644 --- a/docs/zh/guide/deploy.md +++ b/docs/zh/guide/deploy.md @@ -1,9 +1,13 @@ +--- +outline: deep +--- + # Deploy Your VitePress Site The following guides are based on some shared assumptions: -- You are placing your docs inside the `docs` directory of your project. -- You are using the default build output location (`.vitepress/dist`). +- The VitePress site is inside the `docs` directory of your project. +- You are using the default build output directory (`.vitepress/dist`). - VitePress is installed as a local dependency in your project, and you have set up the following scripts in your `package.json`: ```json @@ -15,57 +19,105 @@ The following guides are based on some shared assumptions: } ``` -::: tip +## Build and Test Locally + +1. Run this command to build the docs: + + ```sh + $ npm run docs:build + ``` + +2. Once built, preview it locally by running: + + ```sh + $ npm run docs:preview + ``` + + The `preview` command will boot up a local static web server that will serve the output directory `.vitepress/dist` at `http://localhost:4173`. You can use this to make sure everything looks good before pushing to production. + +3. You can configure the port of the server by passing `--port` as an argument. + + ```json + { + "scripts": { + "docs:preview": "vitepress preview docs --port 8080" + } + } + ``` + +Now the `docs:preview` method will launch the server at `http://localhost:8080`. -If your site is to be served at a subdirectory (`https://example.com/subdir/`), then you have to set `'/subdir/'` as the [`base`](/reference/site-config#base) in your `docs/.vitepress/config.js`. +## Setting a Public Base Path + +By default, we assume the site is going to be deployed at the root path of a domain (`/`). If your site is going to be served at a sub-path, e.g. `https://mywebsite.com/blog/`, then you need to set the [`base`](../reference/site-config#base) option to `'/blog/'` in the VitePress config. **Example:** If you're using Github (or GitLab) Pages and deploying to `user.github.io/repo/`, then set your `base` to `/repo/`. -::: +## HTTP Cache Headers -## Build and Test Locally +If you have control over the HTTP headers on your production server, you can configure `cache-control` headers to achieve better performance on repeated visits. -- You may run this command to build the docs: +The production build uses hashed file names for static assets (JavaScript, CSS and other imported assets not in `public`). If you inspect the production preview using your browser devtools' network tab, you will see files like `app.4f283b18.js`. - ```sh - $ npm run docs:build - ``` +This `4f283b18` hash is generated from the content of this file. The same hashed URL is guaranteed to serve the same file content - if the contents change, the URLs change too. This means you can safely use the strongest cache headers for these files. All such files will be placed under `assets/` in the output directory, so you can configure the following header for them: -- Once you've built the docs, you can test them locally by running: +``` +Cache-Control: max-age=31536000,immutable +``` - ```sh - $ npm run docs:preview - ``` +:::details Example Netlify `_headers` file - The `preview` command will boot up a local static web server that will serve the files from `.vitepress/dist` at `http://localhost:4173`. It's an easy way to check if the production build looks fine in your local environment. +``` +/assets/* + cache-control: max-age=31536000 + cache-control: immutable +``` -- You can configure the port of the server by passing `--port` as an argument. +Note: the `_headers` file should be placed in the [public directory](/guide/asset-handling#the-public-directory) - in our case, `docs/public/_headers` - so that it is copied verbatim to the output directory. - ```json - { - "scripts": { - "docs:preview": "vitepress preview docs --port 8080" +[Netlify custom headers documentation](https://docs.netlify.com/routing/headers/) + +::: + +:::details Example Vercel config in `vercel.json` + +```json +{ + "headers": [ + { + "source": "/assets/(.*)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=31536000, immutable" + } + ] } - } - ``` + ] +} +``` - Now the `docs:preview` method will launch the server at `http://localhost:8080`. +Note: the `vercel.json` file should be placed at the root of your **repository**. -## Netlify, Vercel, AWS Amplify, Cloudflare Pages, Render +[Vercel documentation on headers config](https://vercel.com/docs/concepts/projects/project-configuration#headers) + +::: + +## Platform Guides + +### Netlify / Vercel / Cloudflare Pages / AWS Amplify / Render Set up a new project and change these settings using your dashboard: - **Build Command:** `npm run docs:build` - **Output Directory:** `docs/.vitepress/dist` -- **Node Version:** `14` (or above, by default it usually will be 14 or 16, but on Cloudflare Pages the default is still 12, so you may need to [change that](https://developers.cloudflare.com/pages/platform/build-configuration/)) +- **Node Version:** `16` (or above, by default it usually will be 14 or 16, but on Cloudflare Pages the default is still 12, so you may need to [change that](https://developers.cloudflare.com/pages/platform/build-configuration/)) ::: warning Don't enable options like _Auto Minify_ for HTML code. It will remove comments from output which have meaning to Vue. You may see hydration mismatch errors if they get removed. ::: -## GitHub Pages - -### Using GitHub Actions +### GitHub Pages 1. In your theme config file, `docs/.vitepress/config.js`, set the `base` property to the name of your GitHub repository. 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. @@ -95,7 +147,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f with: node-version: 16 cache: npm - - run: npm install --frozen-lockfile + - run: npm ci - name: Build run: npm run docs:build - uses: actions/configure-pages@v2 @@ -119,9 +171,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f 6. In your repository's Settings under Pages menu item, click `Visit site`, then you can see your site. Your docs will automatically deploy each time you push. -## GitLab Pages - -### Using GitLab CI +### GitLab Pages 1. Set `outDir` in `docs/.vitepress/config.js` to `../public`. @@ -164,7 +214,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f - main ``` -## Azure Static Web Apps +### Azure Static Web Apps 1. Follow the [official documentation](https://docs.microsoft.com/en-us/azure/static-web-apps/build-configuration). @@ -174,7 +224,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f - **`output_location`**: `docs/.vitepress/dist` - **`app_build_command`**: `npm run docs:build` -## Firebase +### Firebase 1. Create `firebase.json` and `.firebaserc` at the root of your project: @@ -205,7 +255,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f firebase deploy ``` -## Surge +### Surge 1. After running `npm run docs:build`, run this command to deploy: @@ -213,7 +263,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f npx surge docs/.vitepress/dist ``` -## Heroku +### Heroku 1. Follow documentation and guide given in [`heroku-buildpack-static`](https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-static). @@ -225,6 +275,6 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f } ``` -## Edgio +### Edgio Refer [Creating and Deploying a VitePress App To Edgio](https://docs.edg.io/guides/vitepress). diff --git a/docs/zh/guide/extending-default-theme.md b/docs/zh/guide/extending-default-theme.md index bcdc40fd..c7459923 100644 --- a/docs/zh/guide/extending-default-theme.md +++ b/docs/zh/guide/extending-default-theme.md @@ -1,6 +1,6 @@ # Extending the Default Theme -VitePress' default theme is optimized for documentation, and can be customized. Consult the [Default Theme Config Overview](/reference/default-theme-config) for a comprehensive list of options. +VitePress' default theme is optimized for documentation, and can be customized. Consult the [Default Theme Config Overview](../reference/default-theme-config) for a comprehensive list of options. However, there are a number of cases where configuration alone won't be enough. For example: @@ -36,6 +36,58 @@ export default DefaultTheme See [default theme CSS variables](https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css) that can be overridden. +## Using Different Fonts + +VitePress uses [Inter](https://rsms.me/inter/) as the default font, and will include the fonts in the build output. The font is also auto preloaded in production. However, this may not be desirable if you want to use a different main font. + +To avoid including Inter in the build output, import the theme from `vitepress/theme-without-fonts` instead: + +```js +// .vitepress/theme/index.js +import DefaultTheme from 'vitepress/theme-without-fonts' +import './my-fonts.css' + +export default DefaultTheme +``` + +```css +/* .vitepress/theme/custom.css */ +:root { + --vp-font-family-base: /* normal text font */ + --vp-font-family-mono: /* code font */ +} +``` + +:::warning +If you are using optional components like the [Team Page](/reference/default-theme-team-page) components, make sure to also import them from `vitepress/theme-without-fonts`! +::: + +If your font is a local file referenced via `@font-face`, it will be processed as an asset and included under `.vitepress/dist/assets` with hashed filename. To preload this file, use the [transformHead](/reference/site-config#transformhead) build hook: + +```js +// .vitepress/config.js +export default { + transformHead({ assets }) { + // adjust the regex accordingly to match your font + const myFontFile = assets.find(file => /font-name\.\w+\.woff2/) + if (myFontFile) { + return [ + [ + 'link', + { + rel: 'preload', + href: myFontFile, + as: 'font', + type: 'font/woff2', + crossorigin: '' + } + ] + ] + } + } +} +``` + ## Registering Global Components ```js @@ -137,3 +189,29 @@ Full list of slots available in the default theme layout: - `nav-bar-content-after` - `nav-screen-content-before` - `nav-screen-content-after` + +## Overriding Internal Components + +You can use Vite's [aliases](https://vitejs.dev/config/shared-options.html#resolve-alias) to replace default theme components with your custom ones: + +```ts +import { fileURLToPath, URL } from 'node:url' +import { defineConfig } from 'vitepress' + +export default defineConfig({ + vite: { + resolve: { + alias: [ + { + find: /^.*\/VPNavBar\.vue$/, + replacement: fileURLToPath( + new URL('./components/CustomNavBar.vue', import.meta.url) + ) + } + ] + } + } +}) +``` + +To know the exact name of the component refer [our source code](https://github.com/vuejs/vitepress/tree/main/src/client/theme-default/components). Since the components are internal, there is a slight chance their name is updated between minor releases. diff --git a/docs/zh/guide/frontmatter.md b/docs/zh/guide/frontmatter.md index e0b15e88..c1856ca4 100644 --- a/docs/zh/guide/frontmatter.md +++ b/docs/zh/guide/frontmatter.md @@ -11,7 +11,7 @@ editLink: true --- ``` -Many site or default theme config options have corresponding options in frontmatter. You can use frontmatter to override specific behavior for the current page only. For details, see [Frontmatter Config Reference](/reference/frontmatter-config). +Many site or default theme config options have corresponding options in frontmatter. You can use frontmatter to override specific behavior for the current page only. For details, see [Frontmatter Config Reference](../reference/frontmatter-config). You can also define custom frontmatter data of your own, to be used in dynamic Vue expressions on the page. @@ -32,7 +32,7 @@ editLink: true Guide content ``` -You can also access current page's frontmatter data in ` +``` + +### Conditional Import + +You can also conditionally import a dependency using the `import.meta.env.SSR` flag (part of [Vite env variables](https://vitejs.dev/guide/env-and-mode.html#env-variables)): + +```js +if (!import.meta.env.SSR) { + import('./lib-that-access-window-on-import').then((module) => { + // use code + }) +} +``` + +Since [`Theme.enhanceApp`](/guide/custom-theme#theme-interface) can be async, you can conditionally import and register Vue plugins that access browser APIs on import: + +```js +// .vitepress/theme/index.js +export default { + // ... + async enhanceApp({ app }) { + if (!import.meta.env.SSR) { + const plugin = await import('plugin-that-access-window-on-import') + app.use(plugin) + } + } +} +``` + +### `defineClientComponent` + +VitePress provides a convenience helper for importing Vue components that access browser APIs on import. + +```vue + + + +``` + +The target component will only be imported in the mounted hook of the wrapper component. diff --git a/docs/zh/guide/using-vue.md b/docs/zh/guide/using-vue.md index f960559e..947ebeff 100644 --- a/docs/zh/guide/using-vue.md +++ b/docs/zh/guide/using-vue.md @@ -4,6 +4,10 @@ In VitePress, each Markdown file is compiled into HTML and then processed as a [ It's worth noting that VitePress leverages Vue's compiler to automatically detect and optimize the purely static parts of the Markdown content. Static contents are optimized into single placeholder nodes and eliminated from the page's JavaScript payload for initial visits. They are also skipped during client-side hydration. In short, you only pay for the dynamic parts on any given page. +:::tip SSR Compatibility +All Vue usage needs to be SSR-compatible. See [SSR Compatibility](./ssr-compat) for details and common workarounds. +::: + ## Templating ### Interpolation @@ -53,7 +57,7 @@ const count = ref(0) The count is: {{ count }} - + ``` -## Browser API Access Restrictions - -Because VitePress applications are server-rendered in Node.js when generating static builds, any Vue usage must conform to the [universal code requirements](https://vuejs.org/guide/scaling-up/ssr.html). In short, make sure to only access Browser / DOM APIs in `beforeMount` or `mounted` hooks. - -If you are using or demoing components that are not SSR-friendly (for example, contain custom directives), you can wrap them inside the built-in `` component: - -```md - - - -``` - -Note this does not fix components or libraries that access Browser APIs **on import**. To use code that assumes a browser environment on import, you need to dynamically import them in proper lifecycle hooks: - -```vue - -``` - -If your module `export default` a Vue component, you can register it dynamically: - -```vue - - - -``` - -**Also see:** - -- [Vue.js > Dynamic Components](https://vuejs.org/guide/essentials/component-basics.html#dynamic-components) - ## Using Teleports -Vitepress currently has SSG support for teleports to body only. For other targets, you can wrap them inside the built-in `` component or inject the teleport markup into the correct location in your final page HTML through [`postRender` hook](/reference/site-config#postrender). +Vitepress currently has SSG support for teleports to body only. For other targets, you can wrap them inside the built-in `` component or inject the teleport markup into the correct location in your final page HTML through [`postRender` hook](../reference/site-config#postrender). @@ -294,7 +241,7 @@ Vitepress currently has SSG support for teleports to body only. For other target ``` - ## Overview ### Config Resolution -The config file is always resolved from `/.vitepress/config.[ext]`, where `` is your VitePress [project root](/guide/routing#root-and-source-directory), and `[ext]` is one of the supported file extensions. TypeScript is supported out of the box. Supported extensions include `.js`, `.ts`, `.cjs`, `.mjs`, `.cts`, and `.mts`. +The config file is always resolved from `/.vitepress/config.[ext]`, where `` is your VitePress [project root](../guide/routing#root-and-source-directory), and `[ext]` is one of the supported file extensions. TypeScript is supported out of the box. Supported extensions include `.js`, `.ts`, `.cjs`, `.mjs`, `.cts`, and `.mts`. It is recommended to use ES modules syntax in config files. The config file should default export an object: @@ -77,6 +63,20 @@ export default defineConfigWithTheme({ }) ``` +### Vite, Vue & Markdown Config + +- **Vite** + + You can configure the underlying Vite instance using the [vite](#vite) option in your VitePress config. No need to create a separate Vite config file. + +- **Vue** + + VitePress already includes the official Vue plugin for Vite ([@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue)). You can configure its options using the [vue](#vue) option in your VitePress config. + +- **Markdown** + + You can configure the underlying [Markdown-It](https://github.com/markdown-it/markdown-it) instance using the [markdown](#markdown) option in your VitePress config. + ## Site Metadata ### title @@ -206,7 +206,7 @@ export default { - Type: `boolean` - Default: `false` -When set to `true`, VitePress will remove the trailing `.html` from URLs. Also see [Generating Clean URL](/guide/routing#generating-clean-url). +When set to `true`, VitePress will remove the trailing `.html` from URLs. Also see [Generating Clean URL](../guide/routing#generating-clean-url). ::: warning Server Support Required Enabling this may require additional configuration on your hosting platform. For it to work, your server must be able to serve `/foo.html` when visiting `/foo` **without a redirect**. @@ -216,7 +216,7 @@ Enabling this may require additional configuration on your hosting platform. For - Type: `Record` -Defines custom directory <-> URL mappings. See [Routing: Route Rewrites](/guide/routing#route-rewrites) for more details. +Defines custom directory <-> URL mappings. See [Routing: Route Rewrites](../guide/routing#route-rewrites) for more details. ```ts export default { @@ -233,7 +233,7 @@ export default { - Type: `string` - Default: `.` -The directory where your markdown pages are stored, relative to project root. Also see [Root and Source Directory](/guide/routing#root-and-source-directory). +The directory where your markdown pages are stored, relative to project root. Also see [Root and Source Directory](../guide/routing#root-and-source-directory). ```ts export default { @@ -259,7 +259,7 @@ export default { - Type: `string` - Default: `./.vitepress/dist` -The build output location for the site, relative to [project root](/guide/routing#root-and-source-directory). +The build output location for the site, relative to [project root](../guide/routing#root-and-source-directory). ```ts export default { @@ -272,7 +272,7 @@ export default { - Type: `string` - Default: `./.vitepress/cache` -The directory for cache files, relative to [project root](/guide/routing#root-and-source-directory). See also: [cacheDir](https://vitejs.dev/config/shared-options.html#cachedir). +The directory for cache files, relative to [project root](../guide/routing#root-and-source-directory). See also: [cacheDir](https://vitejs.dev/config/shared-options.html#cachedir). ```ts export default { @@ -298,7 +298,7 @@ export default { - Type: `boolean` - Default: `false` -When set to `true`, the production app will be built in [MAP Mode](/guide/mpa-mode). MPA mode ships 0kb JavaScript by default, at the cost of disabling client-side navigation and requires explicit opt-in for interactivity. +When set to `true`, the production app will be built in [MAP Mode](../guide/mpa-mode). MPA mode ships 0kb JavaScript by default, at the cost of disabling client-side navigation and requires explicit opt-in for interactivity. ## Theming @@ -320,7 +320,7 @@ This option injects an inline script that restores users settings from local sto - Type: `boolean` - Default: `false` -Whether to get the last updated timestamp for each page using Git. The timestamp will be included in each page's page data, accessible via [`useData`](/reference/runtime-api#usedata). +Whether to get the last updated timestamp for each page using Git. The timestamp will be included in each page's page data, accessible via [`useData`](./runtime-api#usedata). When using the default theme, enabling this option will display each page's last updated time. You can customize the text via [`themeConfig.lastUpdatedText`](./default-theme-config#lastupdatedtext) option. @@ -336,7 +336,15 @@ Configure Markdown parser options. VitePress uses [Markdown-it](https://github.c export default { markdown: { theme: 'material-theme-palenight', - lineNumbers: true + lineNumbers: true, + + // adjust how header anchors are generated, + // useful for integrating with tools that use different conventions + anchors: { + slugify(str) { + return encodeURIComponent(str) + } + } } } ``` @@ -404,12 +412,28 @@ interface MarkdownOptions extends MarkdownIt.Options { Pass raw [Vite Config](https://vitejs.dev/config/) to internal Vite dev server / bundler. +```js +export default { + vite: { + // Vite config options + } +} +``` + ### vue - Type: `import('@vitejs/plugin-vue').Options` Pass raw [`@vitejs/plugin-vue` options](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue#options) to the internal plugin instance. +```js +export default { + vue: { + // @vitejs/plugin-vue options + } +} +``` + ## Build Hooks VitePress build hooks allow you to add new functionality and behaviors to your website: @@ -475,6 +499,8 @@ export default { ```ts interface TransformContext { + page: string // e.g. index.md (relative to srcDir) + assets: string[] // all non-js/css assets as fully resolved public URL siteConfig: SiteConfig siteData: SiteData pageData: PageData