编辑链接
站点级配置
编辑链接允许您显示用于编辑 Git 管理服务(例如 GitHub 或 GitLab)上的页面的链接。要启用它,请将 themeConfig.editLink
选项添加到您的配置中。
js
export default {
themeConfig: {
editLink: {
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path'
}
}
}
pattern
选项定义链接的 URL 结构,而 :path
将替换为页面路径。
您还可以放置一个接受 PageData
作为参数并返回 URL 字符串的纯函数。
js
export default {
themeConfig: {
editLink: {
pattern: ({ filePath }) => {
if (filePath.startsWith('packages/')) {
return `https://github.com/acme/monorepo/edit/main/${filePath}`
} else {
return `https://github.com/acme/monorepo/edit/main/docs/${filePath}`
}
}
}
}
}
它不应该有副作用,也不应该访问其范围之外的任何内容,因为它将在浏览器中序列化并执行。
默认情况下,这将在文档页面底部添加链接文本"编辑此页面"。您可以通过定义text
选项来自定义此文本。
js
export default {
themeConfig: {
editLink: {
pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
text: 'Edit this page on GitHub'
}
}
}
Frontmatter 配置
可以使用 frontmatter 上的editLink
选项在每页上禁用此功能:
yaml
---
editLink: false
---