Skip to content

feat: Add docsRepo #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 23, 2018
9 changes: 7 additions & 2 deletions docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions docs/zh/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ next: false
---
```

## Github 和编辑链接
## Git 仓库和编辑链接

当你提供了 `themeConfig.repo` 选项,将会自动在每个页面的导航栏生成生成一个 GitHub 链接,以及在页面的底部生成一个 `"Edit this page"` 链接。

Expand All @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions lib/default-theme/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default {
repo,
editLinks,
docsDir = '',
docsBranch = 'master'
docsBranch = 'master',
docsRepo = repo
} = this.$site.themeConfig

let path = normalize(this.$page.path)
Expand All @@ -65,10 +66,10 @@ export default {
path += '.md'
}

if (repo && editLinks) {
const base = outboundRE.test(repo)
? repo
: `https://github.com/${repo}`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it just work for github?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can take a full URL to handle repositories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was preserved, I just changed the var name from repo to docsRepo.

if (docsRepo && editLinks) {
const base = outboundRE.test(docsRepo)
? docsRepo
: `https://github.com/${docsRepo}`
return (
base.replace(endingSlashRE, '') +
`/edit/${docsBranch}/` +
Expand Down