diff --git a/__tests__/e2e/dynamic-routes/[id].md b/__tests__/e2e/dynamic-routes/[id].md index a1ca54a0078..ec1b07621f5 100644 --- a/__tests__/e2e/dynamic-routes/[id].md +++ b/__tests__/e2e/dynamic-routes/[id].md @@ -1,8 +1,3 @@ - - -
{{ page.params }}
+
{{ $params }}
diff --git a/__tests__/e2e/static-data/static.data.ts b/__tests__/e2e/static-data/static.data.ts index a9ae896bd15..1a70d74a3a5 100644 --- a/__tests__/e2e/static-data/static.data.ts +++ b/__tests__/e2e/static-data/static.data.ts @@ -1,23 +1,20 @@ import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' - -const dirname = path.dirname(fileURLToPath(import.meta.url)) +import { defineLoader } from 'vitepress' type Data = Record[] export declare const data: Data -export default { +export default defineLoader({ watch: ['./data/*'], - async load(): Promise { + async load(files: string[]): Promise { const foo = fs.readFileSync( - path.resolve(dirname, './data/foo.json'), + files.find((f) => f.endsWith('foo.json'))!, 'utf-8' ) const bar = fs.readFileSync( - path.resolve(dirname, './data/bar.json'), + files.find((f) => f.endsWith('bar.json'))!, 'utf-8' ) return [JSON.parse(foo), JSON.parse(bar)] } -} +}) diff --git a/__tests__/unit/client/theme-default/composables/outline.test.ts b/__tests__/unit/client/theme-default/composables/outline.test.ts index 06180f1a873..f32d68aa99e 100644 --- a/__tests__/unit/client/theme-default/composables/outline.test.ts +++ b/__tests__/unit/client/theme-default/composables/outline.test.ts @@ -7,14 +7,23 @@ describe('client/theme-default/composables/outline', () => { resolveHeaders( [ { - level: 2, - title: 'h2 - 1', - link: '#h2-1' - }, - { - level: 3, - title: 'h3 - 1', - link: '#h3-1' + level: 1, + title: 'h1 - 1', + link: '#h1-1', + children: [ + { + level: 2, + title: 'h2 - 1', + link: '#h2-1', + children: [ + { + level: 3, + title: 'h3 - 1', + link: '#h3-1' + } + ] + } + ] } ], [2, 3] @@ -42,12 +51,14 @@ describe('client/theme-default/composables/outline', () => { { level: 2, title: 'h2 - 1', - link: '#h2-1' - }, - { - level: 3, - title: 'h3 - 1', - link: '#h3-1' + link: '#h2-1', + children: [ + { + level: 3, + title: 'h3 - 1', + link: '#h3-1' + } + ] } ], 2 @@ -68,42 +79,52 @@ describe('client/theme-default/composables/outline', () => { { level: 2, title: 'h2 - 1', - link: '#h2-1' - }, - { - level: 3, - title: 'h3 - 1', - link: '#h3-1' - }, - { - level: 4, - title: 'h4 - 1', - link: '#h4-1' - }, - { - level: 3, - title: 'h3 - 2', - link: '#h3-2' - }, - { - level: 4, - title: 'h4 - 2', - link: '#h4-2' + link: '#h2-1', + children: [ + { + level: 3, + title: 'h3 - 1', + link: '#h3-1', + children: [ + { + level: 4, + title: 'h4 - 1', + link: '#h4-1' + } + ] + }, + { + level: 3, + title: 'h3 - 2', + link: '#h3-2', + children: [ + { + level: 4, + title: 'h4 - 2', + link: '#h4-2' + } + ] + } + ] }, { level: 2, title: 'h2 - 2', - link: '#h2-2' - }, - { - level: 3, - title: 'h3 - 3', - link: '#h3-3' - }, - { - level: 4, - title: 'h4 - 3', - link: '#h4-3' + link: '#h2-2', + children: [ + { + level: 3, + title: 'h3 - 3', + link: '#h3-3', + children: [ + { + level: 4, + title: 'h4 - 3', + link: '#h4-3' + } + ] + } + ] } ], 'deep' diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index c53710e0966..db4a23d9c0d 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -14,19 +14,12 @@ export default defineConfig({ head: [['meta', { name: 'theme-color', content: '#3c8772' }]], - markdown: { - headers: { - level: [0, 0] - } - }, - themeConfig: { nav: nav(), sidebar: { '/guide/': sidebarGuide(), - '/config/': sidebarConfig(), - '/api/': sidebarGuide() + '/reference/': sidebarReference() }, editLink: { @@ -60,14 +53,9 @@ function nav() { return [ { text: 'Guide', link: '/guide/what-is-vitepress', activeMatch: '/guide/' }, { - text: 'Config Reference', - link: '/config/introduction', - activeMatch: '/config/' - }, - { - text: 'Runtime API', - link: '/api/', - activeMatch: '/api/' + text: 'Reference', + link: '/reference/site-config', + activeMatch: '/reference/' }, { text: pkg.version, @@ -93,9 +81,8 @@ function sidebarGuide() { items: [ { text: 'What is VitePress?', link: '/guide/what-is-vitepress' }, { text: 'Getting Started', link: '/guide/getting-started' }, - { text: 'Configuration', link: '/guide/configuration' }, { text: 'Routing', link: '/guide/routing' }, - { text: 'Deploying', link: '/guide/deploying' } + { text: 'Deploy', link: '/guide/deploy' } ] }, { @@ -113,45 +100,112 @@ function sidebarGuide() { text: 'Customization', collapsed: false, items: [ - // { text: 'Default Theme', link: '/guide/default-theme' }, - // { - // text: 'Extending the Default Theme', - // link: '/guide/customization-extending-default-theme' - // }, - { text: 'Building a Custom Theme', link: '/guide/customization-intro' }, + { text: 'Using a Custom Theme', link: '/guide/custom-theme' }, { - text: 'Runtime API', - link: '/api/' + text: 'Extending the Default Theme', + link: '/guide/extending-default-theme' }, - { text: 'Build-Time Data Loading', link: '/guide/data-loading' } + { text: 'Build-Time Data Loading', link: '/guide/data-loading' }, + { text: 'Connecting to a CMS', link: '/guide/cms' } ] }, { - text: 'Migrations', + text: 'Experimental', collapsed: false, items: [ { - text: 'Migration from VuePress', - link: '/guide/migration-from-vuepress' - }, - { - text: 'Migration from VitePress 0.x', - link: '/guide/migration-from-vitepress-0' + text: 'MPA Mode', + link: '/guide/mpa-mode' } ] + }, + // { + // text: 'Migrations', + // collapsed: false, + // items: [ + // { + // text: 'Migration from VuePress', + // link: '/guide/migration-from-vuepress' + // }, + // { + // text: 'Migration from VitePress 0.x', + // link: '/guide/migration-from-vitepress-0' + // } + // ] + // }, + { + text: 'Config & API Reference', + link: '/reference/site-config' } ] } -function sidebarConfig() { +function sidebarReference() { return [ { - text: 'Config Reference', + text: 'Reference', items: [ - { text: 'Introduction', link: '/config/introduction' }, - { text: 'App Config', link: '/config/app-config' }, - { text: 'Default Theme Config', link: '/config/theme-config' }, - { text: 'Frontmatter Config', link: '/config/frontmatter-config' } + { text: 'Site Config', link: '/reference/site-config' }, + { text: 'Frontmatter Config', link: '/reference/frontmatter-config' }, + { text: 'Runtime API', link: '/reference/runtime-api' }, + { text: 'CLI', link: '/reference/cli' }, + { + text: 'Default Theme', + items: [ + { + text: 'Overview', + link: '/reference/default-theme-config' + }, + { + text: 'Nav', + link: '/reference/default-theme-nav' + }, + { + text: 'Sidebar', + link: '/reference/default-theme-sidebar' + }, + { + text: 'Home Page', + link: '/reference/default-theme-home-page' + }, + { + text: 'Footer', + link: '/reference/default-theme-footer' + }, + { + text: 'Layout', + link: '/reference/default-theme-layout' + }, + { + text: 'Badge', + link: '/reference/default-theme-badge' + }, + { + text: 'Team Page', + link: '/reference/default-theme-team-page' + }, + { + text: 'Prev / Next Links', + link: '/reference/default-theme-prev-next-links' + }, + { + text: 'Edit Link', + link: '/reference/default-theme-edit-link' + }, + { + text: 'Last Updated Timestamp', + link: '/reference/default-theme-last-updated' + }, + { + text: 'Algolia Search', + link: '/reference/default-theme-search' + }, + { + text: 'Carbon Ads', + link: '/reference/default-theme-carbon-ads' + } + ] + } ] } ] diff --git a/docs/config/frontmatter-config.md b/docs/config/frontmatter-config.md deleted file mode 100644 index 0a41fbacab9..00000000000 --- a/docs/config/frontmatter-config.md +++ /dev/null @@ -1,192 +0,0 @@ -# Frontmatter Config - -Frontmatter enables page based configuration. In every markdown file, you can use frontmatter config to override app-level or theme config options. Also, there are config options which you can only define in frontmatter. - -```yaml ---- -title: Docs with VitePress -editLink: true ---- -``` - -You can access frontmatter by `$frontmatter` helper inside any markdown file. - -```md -{{ $frontmatter.title }} -``` - -## title - -- Type: `string` - -Title for the page. It's same as [config.title](../config/app-config#title), and it overrides the app config. - -```yaml ---- -title: VitePress ---- -``` - -## titleTemplate - -- Type: `string | boolean` - -The suffix for the title. It's same as [config.titleTemplate](../config/app-config#titletemplate), and it overrides the app config. - -```yaml ---- -title: VitePress -titleTemplate: Vite & Vue powered static site generator ---- -``` - -## description - -- Type: `string` - -Description for the page. It's same as [config.description](../config/app-config#description), and it overrides the app config. - -```yaml ---- -description: VitePress ---- -``` - -## head - -- Type: `HeadConfig[]` - -Specify extra head tags to be injected: - -```yaml ---- -head: - - - meta - - name: description - content: hello - - - meta - - name: keywords - content: super duper SEO ---- -``` - -```ts -type HeadConfig = - | [string, Record] - | [string, Record, string] -``` - -## lastUpdated - -- Type: `boolean` -- Default: `true` - -Whether to display [Last Updated](../guide/theme-last-updated) text in the current page. - -```yaml ---- -lastUpdated: false ---- -``` - -## layout - -- Type: `doc | home | page` -- Default: `doc` - -Determines the layout of the page. - -- `doc` - It applies default documentation styles to the markdown content. -- `home` - Special layout for "Home Page". You may add extra options such as `hero` and `features` to rapidly create beautiful landing page. -- `page` - Behave similar to `doc` but it applies no styles to the content. Useful when you want to create a fully custom page. - -```yaml ---- -layout: doc ---- -``` - -## hero - -- Type: `Hero` - -This option only takes effect when `layout` is set to `home`. - -It defines contents of home hero section. - -```yaml ---- -layout: home - -hero: - name: VitePress - text: Vite & Vue powered static site generator. - tagline: Lorem ipsum... - actions: - - theme: brand - text: Get Started - link: /guide/what-is-vitepress - - theme: alt - text: View on GitHub - link: https://github.com/vuejs/vitepress ---- -``` - -```ts -interface Hero { - // The string shown top of `text`. Comes with brand color - // and expected to be short, such as product name. - name?: string - - // The main text for the hero section. This will be defined - // as `h1` tag. - text: string - - // Tagline displayed below `text`. - tagline?: string - - // Action buttons to display in home hero section. - actions?: HeroAction[] -} - -interface HeroAction { - // Color theme of the button. Defaults to `brand`. - theme?: 'brand' | 'alt' - - // Label of the button. - text: string - - // Destination link of the button. - link: string -} -``` - -## features - -- Type: `Feature[]` - -This option only takes effect when `layout` is set to `home`. - -It defines items to display in features section. - -You may learn more about it in [Theme: Home Page](../guide/theme-home-page). - -## aside - -- Type: `boolean` -- Default: `true` - -If you want the right aside component in `doc` layout not to be shown, set this option to `false`. - -```yaml ---- -aside: false ---- -``` - -## outline - -- Type: `number | [number, number] | 'deep' | false` -- Default: `2` - -The levels of header in the outline to display for the page. It's same as [config.themeConfig.outline](../config/theme-config#outline), and it overrides the theme config. diff --git a/docs/config/introduction.md b/docs/config/introduction.md deleted file mode 100644 index f70829d121b..00000000000 --- a/docs/config/introduction.md +++ /dev/null @@ -1,76 +0,0 @@ -# Introduction - -Place your configuration file at `.vitepress/config.js`. This is where all VitePress-specific files will be placed. - -``` -. -├─ docs -│ ├─ .vitepress -│ │ └─ config.js -│ └─ index.md -└─ package.json -``` - -::: tip -You can also use any of `.ts`, `.cjs`, `.mjs`, `.cts`, `.mts` as the config file extension. -::: - -VitePress comes with 2 types of configuration. One is the [App Config](./app-config) which configures the site's fundamental features such as setting title of the site, or customize how markdown parser works. Second is the [Theme Config](./theme-config) which configures the theme of the site, for example, adding a sidebar, or add features such as "Edit this page on GitHub" link. - -There's also another configuration you may do in [Frontmatter](./frontmatter-config). Frontmatter config can override global config defined in App Config or Theme Config for that specific page. However, there're several options that are only available at frontmatter as well. - -Please refer to the corresponding config page to learn more. - -## Config Intellisense - -Since VitePress ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints: - -```js -/** - * @type {import('vitepress').UserConfig} - */ -const config = { - // ... -} - -export default config -``` - -Alternatively, you can use the `defineConfig` helper at which should provide intellisense without the need for jsdoc annotations: - -```js -import { defineConfig } from 'vitepress' - -export default defineConfig({ - // ... -}) -``` - -VitePress also directly supports TS config files. You can use `.vitepress/config.ts` with the `defineConfig` helper as well. - -## Typed Theme Config - -By default, `defineConfig` helper leverages the theme config type from default theme: - -```ts -import { defineConfig } from 'vitepress' - -export default defineConfig({ - themeConfig: { - // Type is `DefaultTheme.Config` - } -}) -``` - -If you use a custom theme and want type checks for the theme config, you'll need to use `defineConfigWithTheme` instead, and pass the config type for your custom theme via a generic argument: - -```ts -import { defineConfigWithTheme } from 'vitepress' -import { ThemeConfig } from 'your-theme' - -export default defineConfigWithTheme({ - themeConfig: { - // Type is `ThemeConfig` - } -}) -``` diff --git a/docs/guide/asset-handling.md b/docs/guide/asset-handling.md index 132b6b6e95c..c1f46675bf3 100644 --- a/docs/guide/asset-handling.md +++ b/docs/guide/asset-handling.md @@ -1,16 +1,16 @@ # Asset Handling -All Markdown files are compiled into Vue components and processed by [Vite](https://github.com/vitejs/vite). You can, **and should**, reference any assets using relative URLs: +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 ![An image](./image.png) ``` -You can reference static assets in your markdown files, your `*.vue` components in the theme, styles and plain `.css` files either using absolute public paths (based on project root) or relative paths (based on your file system). The latter is similar to the behavior you are used to if you have used `vue-cli` or webpack's `file-loader`. +You can reference static assets in your markdown files, your `*.vue` components in the theme, styles and plain `.css` files either using absolute public paths (based on project root) or relative paths (based on your file system). The latter is similar to the behavior you are used to if you have used Vite, Vue CLI, or webpack's `file-loader`. 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. Similar to `vue-cli`, image assets smaller than 4kb will be base64 inlined. +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 **static** path references, including absolute paths, should be based on your working directory structure. @@ -45,7 +45,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](/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 + + +``` + +The [`useData()`](/reference/runtime-api#usedata) helper provides us with all the runtime data we need to conditionally render different layouts. One of the other data we can access is the current page's frontmatter. We can leverage this to allow the end user to control the layout in each page. For example, the user can indicate the page should use a special home page layout with: + +```md +--- +layout: home +--- +``` + +And we can adjust our theme to handle this: + +```vue{3,12-14} + + + +``` + +You can, of course, split the layout into more components: + +```vue{3-5,12-15} + + + +``` + +Consult the [Runtime API Reference](/reference/runtime-api) for everything available in theme components. In addition, you can leverage [Build-Time Data Loading](./data-loading) to generate data-driven layout - for example, a page that lists all blog posts in the current project. + +## Distributing a Custom Theme + +The easiest way to distribute a custom theme is by providing it as a [template repository on GitHub](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository). + +If you wish to distribute the theme as an npm package, follow these steps: + +1. Export the theme object as the default export in your package entry. + +2. If applicable, export your theme config type definition as `ThemeConfig`. + +3. If your theme requires adjusting the VitePress config, export that config under a package sub-path (e.g. `my-theme/config`) so the user can extend it. + +4. Document the theme config options (both via config file and frontmatter). + +5. Provide clear instructions on how to consume your theme (see below). + +## Consuming a Custom Theme + +To consume an external theme, import and re-export it from the custom theme entry: + +```js +// .vitepress/theme/index.js +import Theme from 'awesome-vitepress-theme' + +export default Theme +``` + +If the theme needs to be extended: + +```js +// .vitepress/theme/index.js +import Theme from 'awesome-vitepress-theme' + +export default { + extends: Theme, + enhanceApp(ctx) { + // ... + } +} +``` + +If the theme requires special VitePress config, you will need to also extend it in your own config: + +```ts +// .vitepress/theme/config.ts +import baseConfig from 'awesome-vitepress-theme/config' + +export default { + // extend theme base config (if needed) + extends: baseConfig +} +``` + +Finally, if the theme provides types for its theme config: + +```ts +// .vitepress/theme/config.ts +import baseConfig from 'awesome-vitepress-theme/config' +import { defineConfigWithTheme } from 'vitepress' +import type { ThemeConfig } from 'awesome-vitepress-theme' + +export default defineConfigWithTheme({ + extends: baseConfig, + themeConfig: { + // Type is `ThemeConfig` + } +}) +``` diff --git a/docs/guide/customization-intro.md b/docs/guide/customization-intro.md deleted file mode 100644 index de8e71c9f2d..00000000000 --- a/docs/guide/customization-intro.md +++ /dev/null @@ -1,228 +0,0 @@ -# Theme Introduction - -VitePress comes with its default theme providing many features out of the box. Learn more about each feature on its dedicated page listed below. - -- [Nav](./theme-nav) -- [Sidebar](./theme-sidebar) -- [Prev Next Link](./theme-prev-next-link) -- [Edit Link](./theme-edit-link) -- [Last Updated](./theme-last-updated) -- [Layout](./theme-layout) -- [Home Page](./theme-home-page) -- [Team Page](./theme-team-page) -- [Badge](./theme-badge) -- [Footer](./theme-footer) -- [Search](./theme-search) -- [Carbon Ads](./theme-carbon-ads) - -If you don't find the features you're looking for, or you would rather create your own theme, you may customize VitePress to fit your requirements. In the following sections, we'll go through each way of customizing the VitePress theme. - -## Using a Custom Theme - -You can enable a custom theme by adding the `.vitepress/theme/index.js` or `.vitepress/theme/index.ts` file (the "theme entry file"). - -``` -. -├─ docs -│ ├─ .vitepress -│ │ ├─ theme -│ │ │ └─ index.js -│ │ └─ config.js -│ └─ index.md -└─ package.json -``` - -A VitePress custom theme is simply an object containing four properties and is defined as follows: - -```ts -interface Theme { - Layout: Component // Vue 3 component - NotFound?: Component - enhanceApp?: (ctx: EnhanceAppContext) => Awaitable - setup?: () => void -} - -interface EnhanceAppContext { - app: App // Vue 3 app instance - router: Router // VitePress router instance - siteData: Ref -} -``` - -The theme entry file should export the theme as its default export: - -```js -// .vitepress/theme/index.js -import Layout from './Layout.vue' - -export default { - // root component to wrap each page - Layout, - - // this is a Vue 3 functional component - NotFound: () => 'custom 404', - - enhanceApp({ app, router, siteData }) { - // app is the Vue 3 app instance from `createApp()`. - // router is VitePress' custom router. `siteData` is - // a `ref` of current site-level metadata. - }, - - setup() { - // this function will be executed inside VitePressApp's - // setup hook. all composition APIs are available here. - } -} -``` - -...where the `Layout` component could look like this: - -```vue - - -``` - -The default export is the only contract for a custom theme. Inside your custom theme, it works just like a normal Vite + Vue 3 application. Do note the theme also needs to be [SSR-compatible](./using-vue#browser-api-access-restrictions). - -To distribute a theme, simply export the object in your package entry. To consume an external theme, import and re-export it from the custom theme entry: - -```js -// .vitepress/theme/index.js -import Theme from 'awesome-vitepress-theme' - -export default Theme -``` - -## Extending the Default Theme - -If you want to extend and customize the default theme, you can import it from `vitepress/theme` and augment it in a custom theme entry. Here are some examples of common customizations: - -### Registering Global Components - -```js -// .vitepress/theme/index.js -import DefaultTheme from 'vitepress/theme' - -export default { - ...DefaultTheme, - enhanceApp(ctx) { - // extend default theme custom behaviour. - DefaultTheme.enhanceApp(ctx) - - // register your custom global components - ctx.app.component('MyGlobalComponent' /* ... */) - } -} -``` - -Since we are using Vite, you can also leverage Vite's [glob import feature](https://vitejs.dev/guide/features.html#glob-import) to auto register a directory of components. - -### Customizing CSS - -The default theme CSS is customizable by overriding root level CSS variables: - -```js -// .vitepress/theme/index.js -import DefaultTheme from 'vitepress/theme' -import './custom.css' - -export default DefaultTheme -``` - -```css -/* .vitepress/theme/custom.css */ -:root { - --vp-c-brand: #646cff; - --vp-c-brand-light: #747bff; -} -``` - -See [default theme CSS variables](https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css) that can be overridden. - -### Layout Slots - -The default theme's `` component has a few slots that can be used to inject content at certain locations of the page. Here's an example of injecting a component into the before outline: - -```js -// .vitepress/theme/index.js -import DefaultTheme from 'vitepress/theme' -import MyLayout from './MyLayout.vue' - -export default { - ...DefaultTheme, - // override the Layout with a wrapper component that - // injects the slots - Layout: MyLayout -} -``` - -```vue - - - - -``` - -Or you could use render function as well. - -```js -// .vitepress/theme/index.js -import { h } from 'vue' -import DefaultTheme from 'vitepress/theme' -import MyComponent from './MyComponent.vue' - -export default { - ...DefaultTheme, - Layout() { - return h(DefaultTheme.Layout, null, { - 'aside-outline-before': () => h(MyComponent) - }) - } -} -``` - -Full list of slots available in the default theme layout: - -- When `layout: 'doc'` (default) is enabled via frontmatter: - - `doc-footer-before` - - `doc-before` - - `doc-after` - - `sidebar-nav-before` - - `sidebar-nav-after` - - `aside-top` - - `aside-bottom` - - `aside-outline-before` - - `aside-outline-after` - - `aside-ads-before` - - `aside-ads-after` -- When `layout: 'home'` is enabled via frontmatter: - - `home-hero-before` - - `home-hero-info` - - `home-hero-image` - - `home-hero-after` - - `home-features-before` - - `home-features-after` -- Always: - - `layout-top` - - `layout-bottom` - - `nav-bar-title-before` - - `nav-bar-title-after` - - `nav-bar-content-before` - - `nav-bar-content-after` - - `nav-screen-content-before` - - `nav-screen-content-after` diff --git a/docs/guide/data-loading.md b/docs/guide/data-loading.md index ee9c1c2babd..0a6134e3994 100644 --- a/docs/guide/data-loading.md +++ b/docs/guide/data-loading.md @@ -1,6 +1,15 @@ +# Build-Time Data Loading + +VitePress provides a feature called **data loaders** that allows you to load arbitrary data and import it from pages or components. The data loading is executed **only at build time**: the resulting data will be serialized as JSON in the final JavaScript bundle. + +Data loaders can be used to fetch remote data, or generate metadata based on local files. For example, you can use data loaders to parse all your local API pages and automatically generate an index of all API entries. + ## Basic Usage +A data loader file must end with either `.data.js` or `.data.ts`. The file should provide a default export of an object with the `load()` method: + ```js +// example.data.js export default { load() { return { @@ -10,30 +19,76 @@ export default { } ``` +The loader module is evaluated only in Node.js, so you can import Node APIs and npm dependencies as needed. + +You can then import data from this file in `.md` pages and `.vue` components using the `data` named export: + +```html + + +
{{ data }}
+``` + +Output: + +```json +{ + "data": "hello" +} +``` + +You'll notice the data loader itself does not export the `data`. It is VitePress calling the `load()` method behind the scenes and implicitly exposing the result via the `data` named export. + +This works even if the loader is async: + ```js export default { async load() { + // fetch remote data return (await fetch('...')).json() } } ``` -## Generating Data Based On Local Files +## Data from Local Files + +When you need to generate data based on local files, you should use the `watch` option in the data loader so that changes made to these files can trigger hot updates. + +The `watch` option is also convenient in that you can use [glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax) to match multiple files. The patterns can be relative to the loader file itself, and the `load()` function will receive the matched files as absolute paths: ```js -import { readDirSync } from 'node:fs' +import fs from 'node:fs' +import parseFrontmatter from 'gray-matter' export default { - watch: ['*.md'], - async load() { - // + // watch all blog posts + watch: ['./posts/*.md'], + load(watchedFiles) { + // watchedFiles will be an array of absolute paths of the matched files. + // generate an array of blog post metadata that can be used to render + // a list in the theme layout + return watchedFiles.map(file => { + const content = fs.readFileSync(file, 'utf-8') + const { data, excerpt } = parseFrontmatter(content) + return { + file, + data, + excerpt + } + }) } } ``` -## Typed Data +## Typed Data Loaders + +When using TypeScript, you can type your loader and `data` export like so: ```ts +import { defineLoader } from 'vitepress' + export interface Data { // data type } @@ -41,9 +96,11 @@ export interface Data { declare const data: Data export { data } -export default { +export default defineLoader({ + // type checked loader options + glob: ['...'], async load(): Promise { // ... } -} +}) ``` diff --git a/docs/guide/deploying.md b/docs/guide/deploy.md similarity index 98% rename from docs/guide/deploying.md rename to docs/guide/deploy.md index 4f5d76de548..904924c516f 100644 --- a/docs/guide/deploying.md +++ b/docs/guide/deploy.md @@ -1,4 +1,4 @@ -# Deploying +# Deploy Your VitePress Site The following guides are based on some shared assumptions: @@ -17,7 +17,7 @@ The following guides are based on some shared assumptions: ::: tip -If your site is to be served at a subdirectory (`https://example.com/subdir/`), then you have to set `'/subdir/'` as the [`base`](../config/app-config#base) in your `docs/.vitepress/config.js`. +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`. **Example:** If you're using Github (or GitLab) Pages and deploying to `user.github.io/repo/`, then set your `base` to `/repo/`. diff --git a/docs/guide/extending-default-theme.md b/docs/guide/extending-default-theme.md new file mode 100644 index 00000000000..88647cecca6 --- /dev/null +++ b/docs/guide/extending-default-theme.md @@ -0,0 +1,138 @@ +# 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. + +However, there are a number of cases where configuration alone won't be enough. For example: + +1. You need to tweak the CSS styling; +2. You need to modify the Vue app instance, for example to register global components; +3. You need to inject custom content into the theme via layout slots. + +These advanced customizations will require using a custom theme that "extends" the default theme. + +:::tip +Before proceeding, make sure to first read [Using a Custom Theme](./custom-theme) to understand how custom themes work. +::: + +## Customizing CSS + +The default theme CSS is customizable by overriding root level CSS variables: + +```js +// .vitepress/theme/index.js +import DefaultTheme from 'vitepress/theme' +import './custom.css' + +export default DefaultTheme +``` + +```css +/* .vitepress/theme/custom.css */ +:root { + --vp-c-brand: #646cff; + --vp-c-brand-light: #747bff; +} +``` + +See [default theme CSS variables](https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css) that can be overridden. + +## Registering Global Components + +```js +// .vitepress/theme/index.js +import DefaultTheme from 'vitepress/theme' + +export default { + extends: DefaultTheme, + enhanceApp(ctx) { + // register your custom global components + ctx.app.component('MyGlobalComponent' /* ... */) + } +} +``` + +Since we are using Vite, you can also leverage Vite's [glob import feature](https://vitejs.dev/guide/features.html#glob-import) to auto register a directory of components. + +## Layout Slots + +The default theme's `` component has a few slots that can be used to inject content at certain locations of the page. Here's an example of injecting a component into the before outline: + +```js +// .vitepress/theme/index.js +import DefaultTheme from 'vitepress/theme' +import MyLayout from './MyLayout.vue' + +export default { + ...DefaultTheme, + // override the Layout with a wrapper component that + // injects the slots + Layout: MyLayout +} +``` + +```vue + + + + +``` + +Or you could use render function as well. + +```js +// .vitepress/theme/index.js +import { h } from 'vue' +import DefaultTheme from 'vitepress/theme' +import MyComponent from './MyComponent.vue' + +export default { + ...DefaultTheme, + Layout() { + return h(DefaultTheme.Layout, null, { + 'aside-outline-before': () => h(MyComponent) + }) + } +} +``` + +Full list of slots available in the default theme layout: + +- When `layout: 'doc'` (default) is enabled via frontmatter: + - `doc-footer-before` + - `doc-before` + - `doc-after` + - `sidebar-nav-before` + - `sidebar-nav-after` + - `aside-top` + - `aside-bottom` + - `aside-outline-before` + - `aside-outline-after` + - `aside-ads-before` + - `aside-ads-after` +- When `layout: 'home'` is enabled via frontmatter: + - `home-hero-before` + - `home-hero-info` + - `home-hero-image` + - `home-hero-after` + - `home-features-before` + - `home-features-after` +- Always: + - `layout-top` + - `layout-bottom` + - `nav-bar-title-before` + - `nav-bar-title-after` + - `nav-bar-content-before` + - `nav-bar-content-after` + - `nav-screen-content-before` + - `nav-screen-content-after` + diff --git a/docs/guide/frontmatter.md b/docs/guide/frontmatter.md index b64a5f54ce5..e0b15e88733 100644 --- a/docs/guide/frontmatter.md +++ b/docs/guide/frontmatter.md @@ -1,6 +1,8 @@ # Frontmatter -Any Markdown file that contains a YAML frontmatter block will be processed by [gray-matter](https://github.com/jonschlinkert/gray-matter). The frontmatter must be at the top of the Markdown file, and must take the form of valid YAML set between triple-dashed lines. Example: +## Usage + +VitePress supports YAML frontmatter in all Markdown files, parsing them with [gray-matter](https://github.com/jonschlinkert/gray-matter). The frontmatter must be at the top of the Markdown file (before any elements including ` + +# Hello +``` + +Client scripts in all theme components will be bundled together, while client script for a specific page will be split for that page only. + +Notice that ` +``` + +### Rendering Raw Content + +Params passed to the page will be serialized in the client JavaScript payload, so you should avoid passing heavy data in params, for example raw Markdown or HTML content fetched from a remote CMS. + +Instead, you can pass such content to each page using the `content` property on each path object: + +```js +export default { + paths() { + async paths() { + const posts = await (await fetch('https://my-cms.com/blog-posts')).json() + + return posts.map((post) => { + return { + params: { id: post.id }, + content: post.content // raw Markdown or HTML + } + }) + } + } +} +``` + +Then, use the following special syntax to render the content as part of the Markdown file itself: + +```md + ``` diff --git a/docs/guide/using-vue.md b/docs/guide/using-vue.md index 9850bfcea13..734ebd54515 100644 --- a/docs/guide/using-vue.md +++ b/docs/guide/using-vue.md @@ -1,8 +1,8 @@ # Using Vue in Markdown -In VitePress, each markdown file is compiled into HTML and then processed as a Vue Single-File Component. This means you can use any Vue features inside the markdown, including dynamic templating, using Vue components, or arbitrary in-page Vue component logic by adding a ` + +## Markdown Content + +The count is: {{ count }} + + + + +``` + +:::warning Avoid ` ``` -## Script & Style Hoisting - -Sometimes you may need to apply some JavaScript or CSS only to the current page. In those cases, you can directly write root-level ` - -## Built-In Components - -VitePress provides Built-In Vue Components like `ClientOnly`, check out the [Global Component Guide](/api/) for more information. - -**Also see:** - -- [Using Components In Headers](#using-components-in-headers) - ## 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. @@ -263,7 +275,7 @@ export default { ## 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](../config/app-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). @@ -284,3 +296,11 @@ Vitepress currently has SSG support for teleports to body only. For other target + + diff --git a/docs/guide/vitepress-init.png b/docs/guide/vitepress-init.png new file mode 100644 index 00000000000..d1805cf7a50 Binary files /dev/null and b/docs/guide/vitepress-init.png differ diff --git a/docs/guide/what-is-vitepress.md b/docs/guide/what-is-vitepress.md index 8b63caf66b6..ec92b375811 100644 --- a/docs/guide/what-is-vitepress.md +++ b/docs/guide/what-is-vitepress.md @@ -1,6 +1,26 @@ # What is VitePress? -VitePress is a [Static Site Generator](https://en.wikipedia.org/wiki/Static_site_generator) (SSG). It is designed for building performant content-centric websites, such as this documentation you are reading right now. It also powers the documentation for [Vue.js](https://vuejs.org/), [Vite](https://vitejs.dev/), and many more. In a nutshell, VitePress takes your source content written in [Markdown](https://en.wikipedia.org/wiki/Markdown), applies a theme to it, and generates a directory of static HTML pages (and necessary asset files) that can be easily deployed anywhere. +VitePress is a [Static Site Generator](https://en.wikipedia.org/wiki/Static_site_generator) (SSG) designed for building fast, content-centric websites. In a nutshell, VitePress takes your source content written in [Markdown](https://en.wikipedia.org/wiki/Markdown), applies a theme to it, and generates static HTML pages that can be easily deployed anywhere. + +
+ +Just want to try it out? Skip to the [Quickstart](./getting-started). + +
+ +## Use Cases + +- **Documentation** + + VitePress ships with a default theme designed for technical documentation, especially those that need to embed interactive demos. It powers this page you are reading right now, along with the documentation for [Vite](https://vitejs.dev/), [Pinia](https://pinia.vuejs.org/), [VueUse](https://vueuse.org/), [Mermaid](https://mermaid.js.org/), [Wikimedia Codex](https://doc.wikimedia.org/codex/latest/), and many more. + + The [official Vue.js documentation](https://vuejs.org/) is also based on VitePress, but uses a custom theme shared between multiple translations. + +- **Blogs, Portfolios, and Marketing Sites** + + VitePress supports [fully customized themes](/guide/custom-theme), with the developer experience of a standard Vite + Vue application. Being built on Vite also means you can directly leverage Vite plugins from its rich ecosystem. In addition, VitePress provides flexible APIs to [load data](/guide/data-loading) (local or remote) and [dynamically generate routes](/guide/routing#dynamic-routes). You can use it to build almost anything as long as the data can be determined at build time. + + The official [Vue.js blog](https://blog.vuejs.org/) is a simple blog that generates its index page based on local content. ## Developer Experience @@ -18,7 +38,7 @@ Unlike many traditional SSGs, a website generated by VitePress is in fact a [Sin - **Fast Initial Load** - The initial visit to any page will be served the static, pre-rendered HTML for maximum loading speed, together with a JavaScript bundle that turns the page into a Vue SPA ("hydration"). The hydration process is extremely fast: on [PageSpeed Insights](https://pagespeed.web.dev/), typical VitePress sites achieve near-perfect performance scores even on low-end mobile devices with a slow network. + The initial visit to any page will be served the static, pre-rendered HTML for blazing fast loading speed and optimal SEO. The page then loads a JavaScript bundle that turns the page into a Vue SPA ("hydration"). The hydration process is extremely fast: on [PageSpeed Insights](https://pagespeed.web.dev/report?url=https%3A%2F%2Fvitepress.vuejs.org%2F), typical VitePress sites achieve near-perfect performance scores even on low-end mobile devices with a slow network. - **Fast Post-load Navigation** @@ -28,14 +48,6 @@ Unlike many traditional SSGs, a website generated by VitePress is in fact a [Sin To be able to hydrate the dynamic Vue parts embedded inside static Markdown, each Markdown page is processed as a Vue component and compiled into JavaScript. This may sound inefficient, but the Vue compiler is smart enough to separate the static and dynamic parts, minimizing both the hydration cost and payload size. For the initial page load, the static parts are automatically eliminated from the JavaScript payload and skipped during hydration. -## Theming & Extensibility - -VitePress ships with a feature-rich default theme designed for documentation purposes. It allows you to spin up a beautiful documentation site like this one with minimal effort, and doesn't require any Vue-specific knowledge. - -VitePress also supports fully customized themes with the developer experience of a standard Vite + Vue application. Being built on Vite also means you can directly leverage Vite plugins from its rich ecosystem. This makes VitePress an ideal choice for building sites that is content-centric but also requires non-trivial interactivity. The [Vue.js documentation](https://github.com/vuejs/docs) is a good example of such customization. - -And of course, you can use it to build a blog! The [official Vue.js blog](https://github.com/vuejs/blog) is also built with VitePress. - ## What About VuePress? VitePress is the spiritual successor of VuePress. The original VuePress was based on Vue 2 and webpack. With Vue 3 and Vite under the hood, VitePress provides significantly better DX, better production performance, a more polished default theme, and a more flexible customization API. diff --git a/docs/index.md b/docs/index.md index e3e88564947..9d283151da6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,7 @@ titleTemplate: Vite & Vue Powered Static Site Generator hero: name: VitePress text: Vite & Vue Powered Static Site Generator - tagline: Simple, powerful, and performant. Meet the modern SSG framework you've always wanted. + tagline: Simple, powerful, and fast. Meet the modern SSG framework you've always wanted. actions: - theme: brand text: Get Started @@ -17,12 +17,22 @@ hero: link: https://github.com/vuejs/vitepress features: - - title: "Vite: The DX that can't be beat" - details: Feel the speed of Vite. Instant server start and lightning fast HMR that stays fast regardless of the app size. - - title: Designed to be simplicity first - details: With Markdown-centered content, it's built to help you focus on writing and deployed with minimum configuration. - - title: Power of Vue meets Markdown - details: Enhance your content with all the features of Vue in Markdown, while being able to customize your site with Vue. - - title: Fully static yet still dynamic - details: Go wild with true SSG + SPA architecture. Static on page load, but engage users with 100% interactivity from there. + - icon: 📝 + title: Focus on Your Content + details: Effortlessly create beautiful documentation sites with just markdown. + - icon: + src: vite.svg + width: 10 + height: 10 + title: Enjoy the Vite DX + details: Instant server start, lightning fast hot updates, and leverage Vite ecosystem plugins. + - icon: + src: vue.svg + width: 10 + height: 10 + title: Customize with Vue + details: Use Vue syntax and components directly in markdown, or build custom themes with Vue components. + - icon: 🚀 + title: Ship Fast Sites + details: Fast initial load with static HTML, fast post-load navigation with client-side routing. --- diff --git a/docs/public/vite.svg b/docs/public/vite.svg new file mode 100644 index 00000000000..de4aeddc12b --- /dev/null +++ b/docs/public/vite.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/docs/public/vue.svg b/docs/public/vue.svg new file mode 100644 index 00000000000..71c1cfb9afa --- /dev/null +++ b/docs/public/vue.svg @@ -0,0 +1,4 @@ + + + + diff --git a/docs/reference/cli.md b/docs/reference/cli.md new file mode 100644 index 00000000000..0536d41e498 --- /dev/null +++ b/docs/reference/cli.md @@ -0,0 +1,74 @@ +# Command Line Interface + +## `vitepress dev` + +Start VitePress dev server using designated directory as root. Defaults to current directory. The `dev` command can also be omitted when running in current directory. + +### Usage + +```sh +# start in current directory, omitting `dev` +vitepress + +# start in sub directory +vitepress dev [root] +``` + +### Options + +| Option | Description | +| - | - | +| `--open [path]` | Open browser on startup (`boolean \| string`) | +| `--port ` | Specify port (`number`) | +| `--base ` | Public base path (default: `/`) (`string`) | +| `--cors` | Enable CORS | +| `--strictPort` | Exit if specified port is already in use (`boolean`) | +| `--force` | Force the optimizer to ignore the cache and re-bundle (`boolean`) | + +## `vitepress build` + +Build the VitePress site for production. + +### Usage + +```sh +vitepress build [root] +``` + +### Options + +| Option | Description | +| - | - | +| `--mpa` (experimental) | Build in [MPA mode](/guide/mpa-mode) without client-side hydration (`boolean`) | +| `--base ` | Public base path (default: `/`) (`string`) | +| `--target ` | Transpile target (default: `"modules"`) (`string`) | +| `--outDir ` | Output directory (default: `.vitepress/dist`) (`string`) | +| `--minify [minifier]` | Enable/disable minification, or specify minifier to use (default: `"esbuild"`) (`boolean \| "terser" \| "esbuild"`) | +| `--assetsInlineLimit ` | Static asset base64 inline threshold in bytes (default: `4096`) (`number`) | + +## `vitepress preview` + +Locally preview the production build. + +### Usage + +```sh +vitepress preview [root] +``` + +### Options + +| Option | Description | +| - | - | +| `--base ` | Public base path (default: `/`) (`string`) | +| `--port ` | Specify port (`number`) | + +## `vitepress init` + +Start the [Setup Wizard](/guide/getting-started#setup-wizard) in current directory. + +### Usage + +```sh +vitepress init +``` diff --git a/docs/guide/theme-badge.md b/docs/reference/default-theme-badge.md similarity index 100% rename from docs/guide/theme-badge.md rename to docs/reference/default-theme-badge.md diff --git a/docs/guide/theme-carbon-ads.md b/docs/reference/default-theme-carbon-ads.md similarity index 100% rename from docs/guide/theme-carbon-ads.md rename to docs/reference/default-theme-carbon-ads.md diff --git a/docs/config/theme-config.md b/docs/reference/default-theme-config.md similarity index 94% rename from docs/config/theme-config.md rename to docs/reference/default-theme-config.md index 43dfc4b7199..1761158f40d 100644 --- a/docs/config/theme-config.md +++ b/docs/reference/default-theme-config.md @@ -64,7 +64,7 @@ export default { - Type: `NavItem` -The configuration for the nav menu item. You may learn more details at [Theme: Nav](../guide/theme-nav#navigation-links). +The configuration for the nav menu item. More details in [Default Theme: Nav](./default-theme-nav#navigation-links). ```js export default { @@ -111,7 +111,7 @@ interface NavItemWithChildren { - Type: `Sidebar` -The configuration for the sidebar menu item. You may learn more details at [Theme: Sidebar](../guide/theme-sidebar). +The configuration for the sidebar menu item. More details in [Default Theme: Sidebar](./default-theme-sidebar). ```js export default { @@ -271,7 +271,7 @@ export interface Footer { - Type: `EditLink` -Edit Link lets you display a link to edit the page on Git management services such as GitHub, or GitLab. See [Theme: Edit Link](../guide/theme-edit-link) for more details. +Edit Link lets you display a link to edit the page on Git management services such as GitHub, or GitLab. See [Default Theme: Edit Link](./default-theme-edit-link) for more details. ```js export default { @@ -310,7 +310,7 @@ export default { - Type: `AlgoliaSearch` -An option to support searching your docs site using [Algolia DocSearch](https://docsearch.algolia.com/docs/what-is-docsearch). Learn more in [Theme: Search](../guide/theme-search) +An option to support searching your docs site using [Algolia DocSearch](https://docsearch.algolia.com/docs/what-is-docsearch). Learn more in [Default Theme: Search](./default-theme-search) ```ts export interface AlgoliaSearchOptions extends DocSearchProps { @@ -344,7 +344,7 @@ export interface CarbonAdsOptions { } ``` -Learn more in [Theme: Carbon Ads](../guide/theme-carbon-ads) +Learn more in [Default Theme: Carbon Ads](./default-theme-carbon-ads) ## docFooter diff --git a/docs/guide/theme-edit-link.md b/docs/reference/default-theme-edit-link.md similarity index 100% rename from docs/guide/theme-edit-link.md rename to docs/reference/default-theme-edit-link.md diff --git a/docs/guide/theme-footer.md b/docs/reference/default-theme-footer.md similarity index 89% rename from docs/guide/theme-footer.md rename to docs/reference/default-theme-footer.md index d59d0e1d4a6..6b62dbf647d 100644 --- a/docs/guide/theme-footer.md +++ b/docs/reference/default-theme-footer.md @@ -36,4 +36,4 @@ export default { } ``` -Note that footer will not be displayed when the [SideBar](./theme-sidebar) is visible. +Note that footer will not be displayed when the [SideBar](/reference/default-theme-sidebar) is visible. diff --git a/docs/guide/theme-home-page.md b/docs/reference/default-theme-home-page.md similarity index 97% rename from docs/guide/theme-home-page.md rename to docs/reference/default-theme-home-page.md index 498af6e18ea..93de38e142b 100644 --- a/docs/guide/theme-home-page.md +++ b/docs/reference/default-theme-home-page.md @@ -1,6 +1,6 @@ # Home Page -VitePress default theme provides a homepage layout, which you can also see used on [the homepage of this site](../). You may use it on any of your pages by specifying `layout: home` in the [frontmatter](./frontmatter). +VitePress default theme provides a homepage layout, which you can also see used on [the homepage of this site](../). You may use it on any of your pages by specifying `layout: home` in the [frontmatter](./frontmatter-config). ```yaml --- @@ -131,7 +131,7 @@ interface Feature { // Link when clicked on feature component. The link can // be both internal or external. // - // e.g. `guide/theme-home-page` or `htttps://example.com` + // e.g. `guid/reference/default-theme-home-page` or `htttps://example.com` link?: string // Link text to be shown inside feature component. Best diff --git a/docs/guide/theme-last-updated.md b/docs/reference/default-theme-last-updated.md similarity index 100% rename from docs/guide/theme-last-updated.md rename to docs/reference/default-theme-last-updated.md diff --git a/docs/guide/theme-layout.md b/docs/reference/default-theme-layout.md similarity index 74% rename from docs/guide/theme-layout.md rename to docs/reference/default-theme-layout.md index 09b5cff8951..5aa7da1fc62 100644 --- a/docs/guide/theme-layout.md +++ b/docs/reference/default-theme-layout.md @@ -1,6 +1,6 @@ # Layout -You may choose the page layout by setting `layout` option to the page [frontmatter](./frontmatter). There are 3 layout options, `doc`, `page`, and `home`. If nothing is specified, then the page is treated as `doc` page. +You may choose the page layout by setting `layout` option to the page [frontmatter](./frontmatter-config). There are 3 layout options, `doc`, `page`, and `home`. If nothing is specified, then the page is treated as `doc` page. ```yaml --- @@ -19,11 +19,11 @@ It also provides documentation specific features listed below. These features ar - Edit Link - Prev Next Link - Outline -- [Carbon Ads](./theme-carbon-ads) +- [Carbon Ads](./default-theme-carbon-ads) ## Page Layout -Option `page` is treated as "blank page". The Markdown will still be parsed, and all of the [Markdown Extensions](./markdown) work as same as `doc` layout, but it wouldn't get any default stylings. +Option `page` is treated as "blank page". The Markdown will still be parsed, and all of the [Markdown Extensions](/guide/markdown) work as same as `doc` layout, but it wouldn't get any default stylings. The page layout will let you style everything by you without VitePress theme affecting the markup. This is useful when you want to create your own custom page. @@ -31,7 +31,7 @@ Note that even in this layout, sidebar will still show up if the page has a matc ## Home Layout -Option `home` will generate templated "Homepage". In this layout, you can set extra options such as `hero` and `features` to customize the content further. Please visit [Theme: Home Page](./theme-home-page) for more details. +Option `home` will generate templated "Homepage". In this layout, you can set extra options such as `hero` and `features` to customize the content further. Please visit [Default Theme: Home Page](/reference/default-theme-home-page) for more details. ## No Layout diff --git a/docs/guide/theme-nav.md b/docs/reference/default-theme-nav.md similarity index 93% rename from docs/guide/theme-nav.md rename to docs/reference/default-theme-nav.md index 2c82d64960b..5c2a92db19f 100644 --- a/docs/guide/theme-nav.md +++ b/docs/reference/default-theme-nav.md @@ -4,7 +4,7 @@ The Nav is the navigation bar displayed on top of the page. It contains the site ## Site Title and Logo -By default, nav shows the title of the site referencing [`config.title`](../config/app-config#title) value. If you would like to change what's displayed on nav, you may define custom text in `themeConfig.siteTitle` option. +By default, nav shows the title of the site referencing [`config.title`](/reference/site-config#title) value. If you would like to change what's displayed on nav, you may define custom text in `themeConfig.siteTitle` option. ```js export default { @@ -35,7 +35,7 @@ export default { } ``` -You can also pass an object as logo if you want to add `alt` attribute or customize it based on dark/light mode. Refer [`themeConfig.logo`](../config/theme-config#logo) for details. +You can also pass an object as logo if you want to add `alt` attribute or customize it based on dark/light mode. Refer [`themeConfig.logo`](/reference/default-theme-config#logo) for details. ## Navigation Links @@ -159,4 +159,4 @@ export default { ## Social Links -Refer [`socialLinks`](../config/theme-config#sociallinks). +Refer [`socialLinks`](/reference/default-theme-config#sociallinks). diff --git a/docs/guide/theme-prev-next-link.md b/docs/reference/default-theme-prev-next-link.md similarity index 100% rename from docs/guide/theme-prev-next-link.md rename to docs/reference/default-theme-prev-next-link.md diff --git a/docs/guide/theme-search.md b/docs/reference/default-theme-search.md similarity index 100% rename from docs/guide/theme-search.md rename to docs/reference/default-theme-search.md diff --git a/docs/guide/theme-sidebar.md b/docs/reference/default-theme-sidebar.md similarity index 98% rename from docs/guide/theme-sidebar.md rename to docs/reference/default-theme-sidebar.md index 67d61dd876c..d46da745b30 100644 --- a/docs/guide/theme-sidebar.md +++ b/docs/reference/default-theme-sidebar.md @@ -1,6 +1,6 @@ # Sidebar -The sidebar is the main navigation block for your documentation. You can configure the sidebar menu in [`themeConfig.sidebar`](/config/theme-config#sidebar). +The sidebar is the main navigation block for your documentation. You can configure the sidebar menu in [`themeConfig.sidebar`](/reference/default-theme-config#sidebar). ```js export default { diff --git a/docs/guide/theme-team-page.md b/docs/reference/default-theme-team-page.md similarity index 98% rename from docs/guide/theme-team-page.md rename to docs/reference/default-theme-team-page.md index 0d0aa88099b..576a56c5537 100644 --- a/docs/guide/theme-team-page.md +++ b/docs/reference/default-theme-team-page.md @@ -68,7 +68,7 @@ If you have large number of members, or simply would like to have more space to ## Create a full Team Page -Instead of adding team members to doc page, you may also create a full Team Page, similar to how you can create a custom [Home Page](./theme-home-page). +Instead of adding team members to doc page, you may also create a full Team Page, similar to how you can create a custom [Home Page](/reference/default-theme-home-page). To create a team page, first, create a new md file. The file name doesn't matter, but here lets call it `team.md`. In this file, set frontmatter option `layout: page`, and then you may compose your page structure using `TeamPage` components. @@ -207,7 +207,7 @@ interface TeamMember { // Social links. e.g. GitHub, Twitter, etc. You may pass in // the Social Links object here. - // See: https://vitepress.vuejs.org/config/theme-config.html#sociallinks + // See: https://vitepress.vuejs.org/reference/default-theme-config.html#sociallinks links?: SocialLink[] // URL for the sponsor page for the member. diff --git a/docs/reference/frontmatter-config.md b/docs/reference/frontmatter-config.md new file mode 100644 index 00000000000..261e338c6c1 --- /dev/null +++ b/docs/reference/frontmatter-config.md @@ -0,0 +1,145 @@ +--- +outline: deep +--- + +# Frontmatter Config + +Frontmatter enables page based configuration. In every markdown file, you can use frontmatter config to override site-level or theme-level config options. Also, there are config options which you can only define in frontmatter. + +Example usage: + +```md +--- +title: Docs with VitePress +editLink: true +--- +``` + +You can access frontmatter data via the `$frontmatter` global in Vue expressions: + +```md +{{ $frontmatter.title }} +``` + +## title + +- Type: `string` + +Title for the page. It's same as [config.title](/reference/site-config#title), and it overrides the site-level config. + +```yaml +--- +title: VitePress +--- +``` + +## titleTemplate + +- Type: `string | boolean` + +The suffix for the title. It's same as [config.titleTemplate](/reference/site-config#titletemplate), and it overrides the site-level config. + +```yaml +--- +title: VitePress +titleTemplate: Vite & Vue powered static site generator +--- +``` + +## description + +- Type: `string` + +Description for the page. It's same as [config.description](/reference/site-config#description), and it overrides the site-level config. + +```yaml +--- +description: VitePress +--- +``` + +## head + +- Type: `HeadConfig[]` + +Specify extra head tags to be injected for the current page. Will be appended after head tags injected by site-level config. + +```yaml +--- +head: + - - meta + - name: description + content: hello + - - meta + - name: keywords + content: super duper SEO +--- +``` + +```ts +type HeadConfig = + | [string, Record] + | [string, Record, string] +``` + +## Default Theme Only + +The following frontmatter options are only applicable when using the default theme. + +### layout + +- Type: `doc | home | page` +- Default: `doc` + +Determines the layout of the page. + +- `doc` - It applies default documentation styles to the markdown content. +- `home` - Special layout for "Home Page". You may add extra options such as `hero` and `features` to rapidly create beautiful landing page. +- `page` - Behave similar to `doc` but it applies no styles to the content. Useful when you want to create a fully custom page. + +```yaml +--- +layout: doc +--- +``` + +### hero + +Defines contents of home hero section when `layout` is set to `home`. More details in [Default Theme: Home Page](/reference/default-theme-home-page). + +### features + +Defines items to display in features section when `layout` is set to `home`. More details in [Default Theme: Home Page](/reference/default-theme-home-page). + +### aside + +- Type: `boolean` +- Default: `true` + +If you want the right aside component in `doc` layout not to be shown, set this option to `false`. + +```yaml +--- +aside: false +--- +``` + +### outline + +- Type: `number | [number, number] | 'deep' | false` +- Default: `2` + +The levels of header in the outline to display for the page. It's same as [config.themeConfig.outline](/reference/default-theme-config#outline), and it overrides the theme config. + +### lastUpdated + +- Type: `boolean` +- Default: `true` + +Whether to display [Last Updated](/reference/default-theme-last-updated) text in the current page. + +```yaml +--- +lastUpdated: false +--- +``` diff --git a/docs/api/index.md b/docs/reference/runtime-api.md similarity index 57% rename from docs/api/index.md rename to docs/reference/runtime-api.md index 3981ee99765..823074c801c 100644 --- a/docs/api/index.md +++ b/docs/reference/runtime-api.md @@ -1,21 +1,37 @@ -# Runtime API Reference +# Runtime API VitePress offers several built-in APIs to let you access app data. VitePress also comes with a few built-in components that can be used globally. The helper methods are globally importable from `vitepress` and are typically used in custom theme Vue components. However, they are also usable inside `.md` pages because markdown files are compiled into Vue [Single-File Components](https://vuejs.org/guide/scaling-up/sfc.html). -Methods that start with `use*` indicates that it is a [Vue 3 Composition API](https://vuejs.org/guide/introduction.html#composition-api) function that can only be used inside `setup()` or `