diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index f4285c0df6..01b6dbf2f1 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -219,6 +219,7 @@ next: false ## Git Repo and Edit Links Providing `themeConfig.repo` auto generates a GitHub link in the navbar and "Edit this page" links at the bottom of each page. +You can override the generated URL of the edit link for a particular page with a `source` attribute in the front matter. ``` js // .vuepress/config.js diff --git a/lib/default-theme/Page.vue b/lib/default-theme/Page.vue index d5668e514b..dd801a0e2f 100644 --- a/lib/default-theme/Page.vue +++ b/lib/default-theme/Page.vue @@ -58,15 +58,18 @@ export default { docsBranch = 'master', docsRepo = repo } = this.$site.themeConfig + const source = this.$page.frontmatter.source - let path = normalize(this.$page.path) - if (endingSlashRE.test(path)) { - path += 'README.md' - } else { - path += '.md' - } + if (source && editLinks) { + return source.replace('/blob/', '/edit/') + } else if (docsRepo && editLinks) { + let path = normalize(this.$page.path) + if (endingSlashRE.test(path)) { + path += 'README.md' + } else { + path += '.md' + } - if (docsRepo && editLinks) { const base = outboundRE.test(docsRepo) ? docsRepo : `https://github.com/${docsRepo}`