mirror of https://github.com/vuejs/vitepress
commit
bd7a9d34c7
@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: 'bug: pending triage'
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<!--
|
|
||||||
NOTE:
|
|
||||||
VitePress is still WIP, and it is not compatible with VuePress.
|
|
||||||
Please do not open issue about default theme missing features or something doesn't work like VuePress.
|
|
||||||
-->
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**System Info**
|
|
||||||
- vitepress version:
|
|
||||||
- vite version:
|
|
||||||
- Node version:
|
|
||||||
- OS version:
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
@ -0,0 +1,60 @@
|
|||||||
|
name: "\U0001F41E Bug report"
|
||||||
|
description: Create a report to help us improve
|
||||||
|
labels: ["bug: pending triage"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
"Thanks for taking the time to fill out this bug report!
|
||||||
|
VitePress is still WIP, and it is not compatible with VuePress.
|
||||||
|
Please do not open issue about default theme missing features or something doesn't work like VuePress."
|
||||||
|
- type: textarea
|
||||||
|
id: bug-description
|
||||||
|
attributes:
|
||||||
|
label: Describe the bug
|
||||||
|
description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks!
|
||||||
|
placeholder: Bug description
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproduction
|
||||||
|
attributes:
|
||||||
|
label: Reproduction
|
||||||
|
description: Steps to reproduce the behavior
|
||||||
|
placeholder: Reproduction
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: expected
|
||||||
|
attributes:
|
||||||
|
label: Expected behavior
|
||||||
|
description: A clear and concise description of what you expected to happen.
|
||||||
|
placeholder: Expected behavior
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: system-info
|
||||||
|
attributes:
|
||||||
|
label: System Info
|
||||||
|
description: Output of `npx envinfo --system --npmPackages vitepress --binaries --browsers`
|
||||||
|
render: shell
|
||||||
|
placeholder: System, Binaries, Browsers
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: additional-context
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any other context or screenshots about the feature request here.
|
||||||
|
- type: checkboxes
|
||||||
|
id: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Validations
|
||||||
|
description: Before submitting the issue, please make sure you do the following
|
||||||
|
options:
|
||||||
|
- label: Follow our [Code of Conduct](https://vuejs.org/coc)
|
||||||
|
required: true
|
||||||
|
- label: Read the [docs](https://vitepress.vuejs.org/).
|
||||||
|
required: true
|
||||||
|
- label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
|
||||||
|
required: true
|
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
@ -0,0 +1,45 @@
|
|||||||
|
name: "\U0001F680 New feature proposal"
|
||||||
|
description: Suggest an idea for this project
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for your interest in the project and taking the time to fill out this feature report!
|
||||||
|
- type: textarea
|
||||||
|
id: feature-description
|
||||||
|
attributes:
|
||||||
|
label: Is your feature request related to a problem? Please describe.
|
||||||
|
description: "A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: suggested-solution
|
||||||
|
attributes:
|
||||||
|
label: Describe the solution you'd like
|
||||||
|
description: A clear and concise description of what you want to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: alternative
|
||||||
|
attributes:
|
||||||
|
label: Describe alternatives you've considered
|
||||||
|
description: A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
- type: textarea
|
||||||
|
id: additional-context
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any other context or screenshots about the feature request here.
|
||||||
|
- type: checkboxes
|
||||||
|
id: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Validations
|
||||||
|
description: Before submitting the issue, please make sure you do the following
|
||||||
|
options:
|
||||||
|
- label: Follow our [Code of Conduct](https://vuejs.org/coc)
|
||||||
|
required: true
|
||||||
|
- label: Read the [docs](https://vitepress.vuejs.org/).
|
||||||
|
required: true
|
||||||
|
- label: Read the [Contributing Guidelines](https://github.com/vuejs/vitepress/blob/master/.github/contributing.md).
|
||||||
|
required: true
|
||||||
|
- label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
|
||||||
|
required: true
|
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||||
|
|
||||||
|
"projectFolder": ".",
|
||||||
|
|
||||||
|
"mainEntryPointFilePath": "./dist/temp/index.d.ts",
|
||||||
|
|
||||||
|
"dtsRollup": {
|
||||||
|
"enabled": true,
|
||||||
|
"untrimmedFilePath": "./dist/client/index.d.ts"
|
||||||
|
},
|
||||||
|
|
||||||
|
"apiReport": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"docModel": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdocMetadata": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"messages": {
|
||||||
|
"compilerMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"extractorMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning",
|
||||||
|
"addToApiReportFile": true
|
||||||
|
},
|
||||||
|
|
||||||
|
"ae-missing-release-tag": {
|
||||||
|
"logLevel": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdocMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning"
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdoc-undefined-tag": {
|
||||||
|
"logLevel": "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||||
|
|
||||||
|
"projectFolder": ".",
|
||||||
|
|
||||||
|
"mainEntryPointFilePath": "./dist/temp/index.d.ts",
|
||||||
|
|
||||||
|
"dtsRollup": {
|
||||||
|
"enabled": true,
|
||||||
|
"untrimmedFilePath": "./dist/node/index.d.ts"
|
||||||
|
},
|
||||||
|
|
||||||
|
"apiReport": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"docModel": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdocMetadata": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"messages": {
|
||||||
|
"compilerMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"extractorMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning",
|
||||||
|
"addToApiReportFile": true
|
||||||
|
},
|
||||||
|
|
||||||
|
"ae-missing-release-tag": {
|
||||||
|
"logLevel": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdocMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "warning"
|
||||||
|
},
|
||||||
|
|
||||||
|
"tsdoc-undefined-tag": {
|
||||||
|
"logLevel": "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
# API Reference
|
||||||
|
|
||||||
|
## Helper Methods
|
||||||
|
|
||||||
|
The following 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.
|
||||||
|
|
||||||
|
Methods that start with `use*` indicates that it is a [Vue 3 Composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) function that can only be used inside `setup()` or `<script setup>`.
|
||||||
|
|
||||||
|
### `useData`
|
||||||
|
|
||||||
|
Returns page-specific data. The returned object has the following type:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface VitePressData {
|
||||||
|
site: Ref<SiteData>
|
||||||
|
page: Ref<PageData>
|
||||||
|
theme: Ref<any> // themeConfig from .vitepress/config.js
|
||||||
|
frontmatter: Ref<PageData['frontmatter']>
|
||||||
|
title: Ref<string>
|
||||||
|
description: Ref<string>
|
||||||
|
lang: Ref<string>
|
||||||
|
localePath: Ref<string>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup>
|
||||||
|
import { useData } from 'vitepress'
|
||||||
|
const { theme } = useData()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<h1>{{ theme.heroText }}</h1>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
### `useRoute`
|
||||||
|
|
||||||
|
Returns the current route object with the following type:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface Route {
|
||||||
|
path: string
|
||||||
|
data: PageData
|
||||||
|
component: Component | null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `useRouter`
|
||||||
|
|
||||||
|
Returns the VitePress router instance so you can programmatically navigate to another page.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface Router {
|
||||||
|
route: Route
|
||||||
|
go: (href?: string) => Promise<void>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `withBase`
|
||||||
|
|
||||||
|
- **Type**: `(path: string) => string`
|
||||||
|
|
||||||
|
Appends the configured [`base`](/config/basics.html#base) to a given URL path. Also see [Base URL](/guide/assets.html#base-url).
|
||||||
|
|
||||||
|
## Global Components
|
||||||
|
|
||||||
|
VitePress comes with few built-in component that can be used globally. You may use these components in your markdown or your custom theme configuration.
|
||||||
|
|
||||||
|
### `<Content/>`
|
||||||
|
|
||||||
|
The `<Content/>` component displays the rendered markdown contents. Useful [when creating your own theme](https://vitepress.vuejs.org/guide/customization.html).
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<template>
|
||||||
|
<h1>Custom Layout!</h1>
|
||||||
|
<Content />
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
### `<ClientOnly/>`
|
||||||
|
|
||||||
|
The `<ClientOnly/>` component renders its slot only at client side.
|
||||||
|
|
||||||
|
Because VitePress applications are server-rendered in Node.js when generating static builds, any Vue usage must conform to the universal code requirements. 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 `ClientOnly` component.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<ClientOnly>
|
||||||
|
<NonSSRFriendlyComponent />
|
||||||
|
</ClientOnly>
|
||||||
|
```
|
@ -1,51 +0,0 @@
|
|||||||
# Customization
|
|
||||||
|
|
||||||
You can develop your custom theme by adding the `.vitepress/theme/index.js` file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
.
|
|
||||||
├─ docs
|
|
||||||
│ ├─ .vitepress
|
|
||||||
│ │ ├─ theme
|
|
||||||
│ │ │ └─ index.js
|
|
||||||
│ │ └─ config.js
|
|
||||||
│ └─ index.md
|
|
||||||
└─ package.json
|
|
||||||
```
|
|
||||||
|
|
||||||
In `.vitepress/theme/index.js`, you must export theme object and register your own theme layout. Let's say you have your own `Layout` component like this.
|
|
||||||
|
|
||||||
```vue
|
|
||||||
<!-- .vitepress/theme/Layout.vue -->
|
|
||||||
<template>
|
|
||||||
<h1>Custom Layout!</h1>
|
|
||||||
<Content /><!-- make sure to include markdown outlet -->
|
|
||||||
</template>
|
|
||||||
```
|
|
||||||
|
|
||||||
Then include it in `.vitepress/theme/index.js`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// .vitepress/theme/index.js
|
|
||||||
import Layout from './Layout.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
Layout,
|
|
||||||
NotFound: () => 'custom 404', // <- this is a Vue 3 functional component
|
|
||||||
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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want to extend the default theme, you can import it from `vitepress/theme`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
// .vitepress/theme/index.js
|
|
||||||
import DefaultTheme from 'vitepress/theme'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
...DefaultTheme
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,89 +0,0 @@
|
|||||||
# Global Computed
|
|
||||||
|
|
||||||
In VitePress, some core [computed properties](https://v3.vuejs.org/guide/computed.html#computed-properties) can be used by the default theme or custom themes. Or directly in Markdown pages using vue, for example using `$frontmatter.title` to access the title defined in the frontmatter section of the page.
|
|
||||||
|
|
||||||
## $site
|
|
||||||
|
|
||||||
This is the `$site` value of the site you're currently reading:
|
|
||||||
|
|
||||||
```js
|
|
||||||
{
|
|
||||||
base: '/',
|
|
||||||
lang: 'en-US',
|
|
||||||
title: 'VitePress',
|
|
||||||
description: 'Vite & Vue powered static site generator.',
|
|
||||||
head: [],
|
|
||||||
locales: {},
|
|
||||||
themeConfig: $themeConfig
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## $themeConfig
|
|
||||||
|
|
||||||
Refers to `$site.themeConfig`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
{
|
|
||||||
locales: {},
|
|
||||||
repo: 'vuejs/vitepress',
|
|
||||||
docsDir: 'docs',
|
|
||||||
editLinks: true,
|
|
||||||
editLinkText: 'Edit this page on GitHub',
|
|
||||||
lastUpdated: 'Last Updated',
|
|
||||||
nav: [...],
|
|
||||||
sidebar: { ... }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## $page
|
|
||||||
|
|
||||||
This is the `$page` value of the page you're currently reading:
|
|
||||||
|
|
||||||
```js
|
|
||||||
{
|
|
||||||
relativePath: 'guide/global-computed.md',
|
|
||||||
title: 'Global Computed',
|
|
||||||
headers: [
|
|
||||||
{ level: 2, title: '$site', slug: 'site' },
|
|
||||||
{ level: 2, title: '$page', slug: '$page' },
|
|
||||||
...
|
|
||||||
],
|
|
||||||
frontmatter: $frontmatter,
|
|
||||||
lastUpdated: 1606297645000
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## $frontmatter
|
|
||||||
|
|
||||||
Reference of `$page.frontmatter`.
|
|
||||||
|
|
||||||
```js
|
|
||||||
{
|
|
||||||
title: 'Docs with VitePress',
|
|
||||||
editLink: true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## $lang
|
|
||||||
|
|
||||||
The language of the current page. Default: `en-US`.
|
|
||||||
|
|
||||||
## $localePath
|
|
||||||
|
|
||||||
The locale path prefix for the current page. Default: `/`.
|
|
||||||
|
|
||||||
## $title
|
|
||||||
|
|
||||||
Value of the `<title>` label used for the current page.
|
|
||||||
|
|
||||||
## $description
|
|
||||||
|
|
||||||
The content value of the `<meta name= "description" content= "...">` for the current page.
|
|
||||||
|
|
||||||
## $withBase
|
|
||||||
|
|
||||||
Helper method to generate correct path by prepending the `base` path configured in `.vitepress/config.js`. It's useful when you want to link to [public files with base path](./assets#public-files).
|
|
||||||
|
|
||||||
```html
|
|
||||||
<img :src="$withBase('/foo.png')" alt="foo" />
|
|
||||||
```
|
|
@ -0,0 +1,157 @@
|
|||||||
|
# Theming
|
||||||
|
|
||||||
|
## Using a Custom Theme
|
||||||
|
|
||||||
|
You can enable a custom theme by adding the `.vitepress/theme/index.js` file (the "theme entry file").
|
||||||
|
|
||||||
|
```bash
|
||||||
|
.
|
||||||
|
├─ docs
|
||||||
|
│ ├─ .vitepress
|
||||||
|
│ │ ├─ theme
|
||||||
|
│ │ │ └─ index.js
|
||||||
|
│ │ └─ config.js
|
||||||
|
│ └─ index.md
|
||||||
|
└─ package.json
|
||||||
|
```
|
||||||
|
|
||||||
|
A VitePress custom theme is simply an object containing three properties and is defined as follows:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface Theme {
|
||||||
|
Layout: Component // Vue 3 component
|
||||||
|
NotFound?: Component
|
||||||
|
enhanceApp?: (ctx: EnhanceAppContext) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EnhanceAppContext {
|
||||||
|
app: App // Vue 3 app instance
|
||||||
|
router: Router // VitePress router instance
|
||||||
|
siteData: Ref<SiteData>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The theme entry file should export the theme as its default export:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// .vitepress/theme/index.js
|
||||||
|
import Layout from './Layout.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
Layout,
|
||||||
|
NotFound: () => 'custom 404', // <- this is a Vue 3 functional component
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
...where the `Layout` component could look like this:
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<!-- .vitepress/theme/Layout.vue -->
|
||||||
|
<template>
|
||||||
|
<h1>Custom Layout!</h1>
|
||||||
|
<Content /><!-- this is where markdown content will be rendered -->
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
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](/guide/using-vue.html#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({ app }) {
|
||||||
|
// register global components
|
||||||
|
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 {
|
||||||
|
--c-brand: #646cff;
|
||||||
|
--c-brand-light: #747bff;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See [default theme CSS variables](https://github.com/vuejs/vitepress/blob/master/src/client/theme-default/styles/vars.css) that can be overridden.
|
||||||
|
|
||||||
|
### Layout Slots
|
||||||
|
|
||||||
|
The default theme's `<Layout/>` 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 top of the sidebar:
|
||||||
|
|
||||||
|
```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
|
||||||
|
<!--.vitepress/theme/MyLayout.vue-->
|
||||||
|
<script setup>
|
||||||
|
import DefaultTheme from 'vitepress/theme'
|
||||||
|
const { Layout } = DefaultTheme
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Layout>
|
||||||
|
<template #sidebar-top>
|
||||||
|
My custom sidebar top content
|
||||||
|
</template>
|
||||||
|
</Layout>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
Full list of slots available in the default theme layout:
|
||||||
|
|
||||||
|
- `navbar-search`
|
||||||
|
- `sidebar-top`
|
||||||
|
- `sidebar-bottom`
|
||||||
|
- `page-top-ads`
|
||||||
|
- `page-top`
|
||||||
|
- `page-bottom`
|
||||||
|
- `page-bottom-ads`
|
||||||
|
- Only when `home: true` is enabled via frontmatter:
|
||||||
|
- `home-hero`
|
||||||
|
- `home-features`
|
||||||
|
- `home-footer`
|
@ -0,0 +1,7 @@
|
|||||||
|
[build.environment]
|
||||||
|
NODE_VERSION = "16"
|
||||||
|
NPM_FLAGS = "--version" # prevent Netlify npm install
|
||||||
|
|
||||||
|
[build]
|
||||||
|
publish = "docs/.vitepress/dist"
|
||||||
|
command = "npx pnpm i --store=node_modules/.pnpm-store && npm run ci-docs"
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
|||||||
|
packages:
|
||||||
|
- examples/*
|
||||||
|
- docs
|
@ -0,0 +1,35 @@
|
|||||||
|
import { defineConfig } from 'rollup'
|
||||||
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
||||||
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
|
import esbuild from 'rollup-plugin-esbuild'
|
||||||
|
import json from '@rollup/plugin-json'
|
||||||
|
import alias from '@rollup/plugin-alias'
|
||||||
|
import { resolve } from 'path'
|
||||||
|
|
||||||
|
const r = (p) => resolve(__dirname, '../', p)
|
||||||
|
const pkg = require('../package.json')
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
input: [r('src/node/index.ts'), r('src/node/cli.ts')],
|
||||||
|
output: {
|
||||||
|
format: 'cjs',
|
||||||
|
dir: r('dist/node')
|
||||||
|
},
|
||||||
|
external: [...Object.keys(pkg.dependencies), 'buffer', 'punycode'],
|
||||||
|
plugins: [
|
||||||
|
alias({
|
||||||
|
entries: {
|
||||||
|
'readable-stream': 'stream'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
nodeResolve(),
|
||||||
|
esbuild({
|
||||||
|
target: 'node12'
|
||||||
|
}),
|
||||||
|
json()
|
||||||
|
],
|
||||||
|
onwarn(warning, warn) {
|
||||||
|
if (warning.code !== 'EVAL') warn(warning)
|
||||||
|
}
|
||||||
|
})
|
@ -1,9 +0,0 @@
|
|||||||
import { Ref, computed } from 'vue'
|
|
||||||
import { usePageData } from './pageData'
|
|
||||||
|
|
||||||
export type FrontmatterRef = Ref<Record<string, any>>
|
|
||||||
|
|
||||||
export function useFrontmatter() {
|
|
||||||
const pageData = usePageData()
|
|
||||||
return computed(() => pageData.value.frontmatter)
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Ref, computed } from 'vue'
|
|
||||||
import { PageData } from '/@types/shared'
|
|
||||||
import { Route, useRoute } from '../router'
|
|
||||||
|
|
||||||
export type PageDataRef = Ref<PageData>
|
|
||||||
|
|
||||||
export function usePageData(route?: Route) {
|
|
||||||
const r = route || useRoute()
|
|
||||||
|
|
||||||
return computed(() => r.data)
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
import serialized from '@siteData'
|
|
||||||
import { SiteData } from '/@types/shared'
|
|
||||||
import { Ref, ref, readonly } from 'vue'
|
|
||||||
|
|
||||||
export type SiteDataRef<T = any> = Ref<SiteData<T>>
|
|
||||||
|
|
||||||
export const siteDataRef: Ref<SiteData> = ref(parse(serialized))
|
|
||||||
|
|
||||||
export function useSiteData<T = any>() {
|
|
||||||
return siteDataRef as Ref<SiteData<T>>
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse(data: string): SiteData {
|
|
||||||
return readonly(JSON.parse(data)) as SiteData
|
|
||||||
}
|
|
||||||
|
|
||||||
// hmr
|
|
||||||
if (import.meta.hot) {
|
|
||||||
import.meta.hot!.accept('/@siteData', (m) => {
|
|
||||||
siteDataRef.value = parse(m.default)
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
import { computed } from 'vue'
|
|
||||||
import { resolveSiteDataByRoute } from '/@shared/config'
|
|
||||||
import { siteDataRef } from './siteData'
|
|
||||||
import { Route, useRoute } from '../router'
|
|
||||||
|
|
||||||
export function useSiteDataByRoute(route?: Route) {
|
|
||||||
const r = route || useRoute()
|
|
||||||
|
|
||||||
return computed(() => {
|
|
||||||
return resolveSiteDataByRoute(siteDataRef.value, r.path)
|
|
||||||
})
|
|
||||||
}
|
|
@ -0,0 +1,72 @@
|
|||||||
|
import { InjectionKey, Ref, shallowRef, readonly, computed, inject } from 'vue'
|
||||||
|
import { Route } from './router'
|
||||||
|
import serializedSiteData from '@siteData'
|
||||||
|
import { resolveSiteDataByRoute, PageData, SiteData } from '../shared'
|
||||||
|
import { withBase } from './utils'
|
||||||
|
|
||||||
|
export const dataSymbol: InjectionKey<VitePressData> = Symbol()
|
||||||
|
|
||||||
|
export interface VitePressData<T = any> {
|
||||||
|
site: Ref<SiteData<T>>
|
||||||
|
page: Ref<PageData>
|
||||||
|
theme: Ref<T>
|
||||||
|
frontmatter: Ref<PageData['frontmatter']>
|
||||||
|
title: Ref<string>
|
||||||
|
description: Ref<string>
|
||||||
|
lang: Ref<string>
|
||||||
|
localePath: Ref<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
// site data is a singleton
|
||||||
|
export type SiteDataRef<T = any> = Ref<SiteData<T>>
|
||||||
|
|
||||||
|
export const siteDataRef: Ref<SiteData> = shallowRef(parse(serializedSiteData))
|
||||||
|
|
||||||
|
function parse(data: string): SiteData {
|
||||||
|
return readonly(JSON.parse(data)) as SiteData
|
||||||
|
}
|
||||||
|
|
||||||
|
// hmr
|
||||||
|
if (import.meta.hot) {
|
||||||
|
import.meta.hot!.accept('/@siteData', (m) => {
|
||||||
|
siteDataRef.value = parse(m.default)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// per-app data
|
||||||
|
export function initData(route: Route): VitePressData {
|
||||||
|
const site = computed(() =>
|
||||||
|
resolveSiteDataByRoute(siteDataRef.value, route.path)
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
site,
|
||||||
|
theme: computed(() => site.value.themeConfig),
|
||||||
|
page: computed(() => route.data),
|
||||||
|
frontmatter: computed(() => route.data.frontmatter),
|
||||||
|
lang: computed(() => site.value.lang),
|
||||||
|
localePath: computed(() => {
|
||||||
|
const { langs, lang } = site.value
|
||||||
|
const path = Object.keys(langs).find(
|
||||||
|
(langPath) => langs[langPath].lang === lang
|
||||||
|
)
|
||||||
|
return withBase(path || '/')
|
||||||
|
}),
|
||||||
|
title: computed(() => {
|
||||||
|
return route.data.title
|
||||||
|
? route.data.title + ' | ' + site.value.title
|
||||||
|
: site.value.title
|
||||||
|
}),
|
||||||
|
description: computed(() => {
|
||||||
|
return route.data.description || site.value.description
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useData<T = any>(): VitePressData<T> {
|
||||||
|
const data = inject(dataSymbol)
|
||||||
|
if (!data) {
|
||||||
|
throw new Error('vitepress data not properly injected in app')
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
@ -1,95 +0,0 @@
|
|||||||
import { App, defineAsyncComponent } from 'vue'
|
|
||||||
import { joinPath } from './utils'
|
|
||||||
import { SiteDataRef } from './composables/siteData'
|
|
||||||
import { PageDataRef } from './composables/pageData'
|
|
||||||
import { Content } from './components/Content'
|
|
||||||
import { ClientOnly } from './components/ClientOnly'
|
|
||||||
|
|
||||||
export function mixinGlobalComputed(
|
|
||||||
app: App,
|
|
||||||
site: SiteDataRef,
|
|
||||||
siteByRoute: SiteDataRef,
|
|
||||||
page: PageDataRef
|
|
||||||
): void {
|
|
||||||
Object.defineProperties(app.config.globalProperties, {
|
|
||||||
$site: {
|
|
||||||
get() {
|
|
||||||
return site.value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$siteByRoute: {
|
|
||||||
get() {
|
|
||||||
return siteByRoute.value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$themeConfig: {
|
|
||||||
get() {
|
|
||||||
return siteByRoute.value.themeConfig
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$page: {
|
|
||||||
get() {
|
|
||||||
return page.value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$frontmatter: {
|
|
||||||
get() {
|
|
||||||
return page.value.frontmatter
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$lang: {
|
|
||||||
get() {
|
|
||||||
return siteByRoute.value.lang
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$localePath: {
|
|
||||||
get() {
|
|
||||||
const { locales } = site.value
|
|
||||||
const { lang } = siteByRoute.value
|
|
||||||
|
|
||||||
const path = Object.keys(locales).find(
|
|
||||||
(lp) => locales[lp].lang === lang
|
|
||||||
)
|
|
||||||
|
|
||||||
return (locales && path) || '/'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$title: {
|
|
||||||
get() {
|
|
||||||
return page.value.title
|
|
||||||
? page.value.title + ' | ' + siteByRoute.value.title
|
|
||||||
: siteByRoute.value.title
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$description: {
|
|
||||||
get() {
|
|
||||||
return page.value.description || siteByRoute.value.description
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
$withBase: {
|
|
||||||
value(path: string) {
|
|
||||||
return joinPath(site.value.base, path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mixinGlobalComponents(app: App) {
|
|
||||||
app.component('Content', Content)
|
|
||||||
app.component('ClientOnly', ClientOnly)
|
|
||||||
app.component(
|
|
||||||
'Debug',
|
|
||||||
import.meta.env.PROD
|
|
||||||
? () => null
|
|
||||||
: defineAsyncComponent(() => import('./components/Debug.vue'))
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,12 +1,12 @@
|
|||||||
<template>
|
|
||||||
<ul v-if="items.length > 0" class="sidebar-links">
|
|
||||||
<SideBarLink v-for="item of items" :key="item.text" :item="item" />
|
|
||||||
</ul>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useSideBar } from '../composables/sideBar'
|
import { useSideBar } from '../composables/sideBar'
|
||||||
import { SideBarLink } from './SideBarLink'
|
import { SideBarLink } from './SideBarLink'
|
||||||
|
|
||||||
const items = useSideBar()
|
const items = useSideBar()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ul v-if="items.length > 0" class="sidebar-links">
|
||||||
|
<SideBarLink v-for="item of items" :item="item" />
|
||||||
|
</ul>
|
||||||
|
</template>
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { useSiteData, joinPath } from 'vitepress'
|
|
||||||
|
|
||||||
export function useUrl() {
|
|
||||||
const site = useSiteData()
|
|
||||||
|
|
||||||
function withBase(path: string): string {
|
|
||||||
return joinPath(site.value.base, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
withBase
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
import { build } from 'vite'
|
||||||
|
import { SiteConfig } from '..'
|
||||||
|
import { RollupOutput } from 'rollup'
|
||||||
|
|
||||||
|
const virtualEntry = 'client.js'
|
||||||
|
|
||||||
|
export async function buildMPAClient(
|
||||||
|
js: Record<string, string>,
|
||||||
|
config: SiteConfig
|
||||||
|
): Promise<RollupOutput> {
|
||||||
|
const files = Object.keys(js)
|
||||||
|
const themeFiles = files.filter((f) => !f.endsWith('.md'))
|
||||||
|
const pages = files.filter((f) => f.endsWith('.md'))
|
||||||
|
|
||||||
|
return build({
|
||||||
|
root: config.srcDir,
|
||||||
|
base: config.site.base,
|
||||||
|
logLevel: 'warn',
|
||||||
|
build: {
|
||||||
|
emptyOutDir: false,
|
||||||
|
outDir: config.outDir,
|
||||||
|
rollupOptions: {
|
||||||
|
input: [virtualEntry, ...pages]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
name: 'vitepress-mpa-client',
|
||||||
|
resolveId(id) {
|
||||||
|
if (id === virtualEntry) {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
load(id) {
|
||||||
|
if (id === virtualEntry) {
|
||||||
|
return themeFiles
|
||||||
|
.map((file) => `import ${JSON.stringify(file)}`)
|
||||||
|
.join('\n')
|
||||||
|
} else if (id in js) {
|
||||||
|
return js[id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}) as Promise<RollupOutput>
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue