mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
3 years ago
|
# Edit Link
|
||
|
|
||
2 years ago
|
## Site-Level Config
|
||
|
|
||
3 years ago
|
Edit Link lets you display a link to edit the page on Git management services such as GitHub, or GitLab. To enable it, add `themeConfig.editLink` options to your config.
|
||
|
|
||
|
```js
|
||
|
export default {
|
||
|
themeConfig: {
|
||
|
editLink: {
|
||
|
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
The `pattern` option defines the URL structure for the link, and `:path` is going to be replaced with the page path.
|
||
|
|
||
2 years ago
|
You can also put a pure function that accepts [`PageData`](./runtime-api#usedata) as the argument and returns the URL string.
|
||
2 years ago
|
|
||
|
```js
|
||
|
export default {
|
||
|
themeConfig: {
|
||
|
editLink: {
|
||
2 years ago
|
pattern: ({ filePath }) => {
|
||
|
if (filePath.startsWith('packages/')) {
|
||
|
return `https://github.com/acme/monorepo/edit/main/${filePath}`
|
||
2 years ago
|
} else {
|
||
2 years ago
|
return `https://github.com/acme/monorepo/edit/main/docs/${filePath}`
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
It should not have side-effects nor access anything outside of its scope since it will be serialized and executed in the browser.
|
||
|
|
||
3 years ago
|
By default, this will add the link text "Edit this page" at the bottom of the doc page. You may customize this text by defining the `text` option.
|
||
|
|
||
|
```js
|
||
|
export default {
|
||
|
themeConfig: {
|
||
|
editLink: {
|
||
|
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
|
||
|
text: 'Edit this page on GitHub'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
2 years ago
|
|
||
|
## Frontmatter Config
|
||
|
|
||
|
This can be disabled per-page using the `editLink` option on frontmatter:
|
||
|
|
||
|
```yaml
|
||
|
---
|
||
2 years ago
|
editLink: false
|
||
2 years ago
|
---
|
||
|
```
|