编辑按钮
站点级别的配置
编辑按钮显示为一个链接,指向 Github 或 GitLab 中的 Git 管理页面。通过配置 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}`
}
}
}
}
}
该函数不应有副作用,也不应访问其作用域外的数据,因为它会被序列化并在浏览器中执行。
默认情况下,会在页面底部添加 "Edit this page" 链接,可以通过设置 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
---