From 716aefec55f34ef086fe1dd07d3a7648d1586391 Mon Sep 17 00:00:00 2001 From: wangyi7099 Date: Mon, 23 Apr 2018 22:58:23 +0800 Subject: [PATCH] feat: Add docsRepo (#155) --- docs/default-theme-config/README.md | 9 +++++++-- docs/zh/default-theme-config/README.md | 18 +++++++++++++----- lib/default-theme/Page.vue | 11 ++++++----- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index 68ae6995a1..f4285c0df6 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -229,9 +229,14 @@ module.exports = { // Customising the header label // Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo` repoLabel: 'Contribute!', - // if your docs are not at the root of the repo + + // Optional options for generating "Edit this page" link + + // if your docs are in a different repo from your main project: + docsRepo: 'vuejs/vuepress', + // if your docs are not at the root of the repo: docsDir: 'docs', - // optional, defaults to master + // if your docs are in a specific branch (defaults to 'master'): docsBranch: 'master', // defaults to true, set to false to disable editLinks: true, diff --git a/docs/zh/default-theme-config/README.md b/docs/zh/default-theme-config/README.md index 1238d8330c..4aaff71a68 100644 --- a/docs/zh/default-theme-config/README.md +++ b/docs/zh/default-theme-config/README.md @@ -214,7 +214,7 @@ next: false --- ``` -## Github 和编辑链接 +## Git 仓库和编辑链接 当你提供了 `themeConfig.repo` 选项,将会自动在每个页面的导航栏生成生成一个 GitHub 链接,以及在页面的底部生成一个 `"Edit this page"` 链接。 @@ -224,10 +224,18 @@ module.exports = { themeConfig: { // 假定是 GitHub. 同时也可以是一个完整的 GitLab URL repo: 'vuejs/vuepress', - // 当你的文档不是仓库的根目录时需要设置 - docsDir: 'docs', - // 可选的, 默认是 master - docsBranch: 'master', +    // 自定义仓库链接文字。默认从 `themeConfig.repo` 中自动推断为 +    // "GitHub"/"GitLab"/"Bitbucket" 其中之一,或是 "Source"。 +    repoLabel: '查看源码', + +    // 以下为可选的编辑链接选项 + +    // 假如你的文档仓库和项目本身不在一个仓库: +    docsRepo: 'vuejs/vuepress', +    // 假如文档不是放在仓库的根目录下: +    docsDir: 'docs', +    // 假如文档放在一个特定的分支下: +    docsBranch: 'master', // 默认是 true, 设置为 false 来禁用 editLinks: true, // 默认为 "Edit this page" diff --git a/lib/default-theme/Page.vue b/lib/default-theme/Page.vue index 029a96f358..d5668e514b 100644 --- a/lib/default-theme/Page.vue +++ b/lib/default-theme/Page.vue @@ -55,7 +55,8 @@ export default { repo, editLinks, docsDir = '', - docsBranch = 'master' + docsBranch = 'master', + docsRepo = repo } = this.$site.themeConfig let path = normalize(this.$page.path) @@ -65,10 +66,10 @@ export default { path += '.md' } - if (repo && editLinks) { - const base = outboundRE.test(repo) - ? repo - : `https://github.com/${repo}` + if (docsRepo && editLinks) { + const base = outboundRE.test(docsRepo) + ? docsRepo + : `https://github.com/${docsRepo}` return ( base.replace(endingSlashRE, '') + `/edit/${docsBranch}/` +