Skip to content

Commit 8a5055b

Browse files
feat(theme-default): support full link for github repo (#152)
Co-authored-by: meteorlxy <[email protected]>
1 parent a38f2a2 commit 8a5055b

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

docs/reference/default-theme/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module.exports = {
146146
// If you set it in the form of `organization/repository`
147147
// we will take it as a GitHub repo
148148
repo: 'vuejs/vuepress',
149-
// Use url directly if you are not using GitHub
149+
// You can also set it to a URL directly
150150
repo: 'https://gitlab.com/foo/bar',
151151
},
152152
}
@@ -362,7 +362,7 @@ module.exports = {
362362

363363
This will be used for generating the _edit this page_ link.
364364

365-
If you don't set this option, the pattern will be inferred from the [docsRepo](#docsrepo) option. But if your documentation repository is not hosted on a common platform, for example, GitHub, GitLab, Bitbucket, etc., you have to set this option explicitly to make the _edit this page_ link work.
365+
If you don't set this option, the pattern will be inferred from the [docsRepo](#docsrepo) option. But if your documentation repository is not hosted on a common platform, for example, GitHub, GitLab, Bitbucket, Gitee, etc., you have to set this option explicitly to make the _edit this page_ link work.
366366

367367
- Usage:
368368

docs/zh/reference/default-theme/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module.exports = {
146146
// 如果你按照 `organization/repository` 的格式设置它
147147
// 我们会将它作为一个 GitHub 仓库
148148
repo: 'vuejs/vuepress',
149-
// 如果你使用的不是 GitHub ,可以直接使用 URL
149+
// 你也可以直接将它设置为一个 URL
150150
repo: 'https://gitlab.com/foo/bar',
151151
},
152152
}
@@ -362,7 +362,7 @@ module.exports = {
362362

363363
它将会用于生成 _编辑此页_ 的链接。
364364

365-
如果你不设置该选项,则会根据 [docsRepo](#docsrepo) 配置项来推断 Pattern 。但是如果你的文档仓库没有托管在常用的平台上,比如 GitHub 、 GitLab 、 Bitbucket 等,那么你必须设置该选项才能使 _编辑此页_ 链接正常工作。
365+
如果你不设置该选项,则会根据 [docsRepo](#docsrepo) 配置项来推断 Pattern 。但是如果你的文档仓库没有托管在常用的平台上,比如 GitHub 、 GitLab 、 Bitbucket 、 Gitee 等,那么你必须设置该选项才能使 _编辑此页_ 链接正常工作。
366366

367367
- 用法:
368368

packages/@vuepress/theme-default/src/client/components/NavbarLinks.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { computed, defineComponent } from 'vue'
1313
import type { ComputedRef } from 'vue'
1414
import { useRouter } from 'vue-router'
1515
import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
16-
import { isString } from '@vuepress/shared'
16+
import { isLinkHttp, isString } from '@vuepress/shared'
1717
import type { NavbarItem, NavbarGroup, ResolvedNavbarItem } from '../../shared'
1818
import { useNavLink, useThemeLocaleData } from '../composables'
1919
import { resolveRepoType } from '../utils'
@@ -96,9 +96,10 @@ const useNavbarRepo = (): ComputedRef<ResolvedNavbarItem[]> => {
9696
)
9797
9898
const repoLink = computed(() => {
99-
if (repoType.value === 'GitHub') {
99+
if (repo.value && !isLinkHttp(repo.value)) {
100100
return `https://github.com/${repo.value}`
101101
}
102+
102103
return repo.value
103104
})
104105

packages/@vuepress/theme-default/src/client/utils/resolveEditLink.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { removeLeadingSlash, removeEndingSlash } from '@vuepress/shared'
1+
import {
2+
isLinkHttp,
3+
removeLeadingSlash,
4+
removeEndingSlash,
5+
} from '@vuepress/shared'
26
import { resolveRepoType } from './resolveRepoType'
37
import type { RepoType } from './resolveRepoType'
48

@@ -38,7 +42,7 @@ export const resolveEditLink = ({
3842
return pattern
3943
.replace(
4044
/:repo/,
41-
repoType === 'GitHub' ? `https://github.com/${docsRepo}` : docsRepo
45+
isLinkHttp(docsRepo) ? docsRepo : `https://github.com/${docsRepo}`
4246
)
4347
.replace(/:branch/, docsBranch)
4448
.replace(

packages/@vuepress/theme-default/src/client/utils/resolveRepoType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isLinkHttp } from '@vuepress/shared'
33
export type RepoType = 'GitHub' | 'GitLab' | 'Gitee' | 'Bitbucket' | null
44

55
export const resolveRepoType = (repo: string): RepoType => {
6-
if (!isLinkHttp(repo)) return 'GitHub'
6+
if (!isLinkHttp(repo) || /github\.com/.test(repo)) return 'GitHub'
77
if (/bitbucket\.org/.test(repo)) return 'Bitbucket'
88
if (/gitlab\.com/.test(repo)) return 'GitLab'
99
if (/gitee\.com/.test(repo)) return 'Gitee'

0 commit comments

Comments
 (0)