編輯連結
網站層級設定
編輯連結讓您在 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
---