1
1
import { removeLeadingSlash , removeEndingSlash } from '@vuepress/shared'
2
2
import { resolveRepoType } from './resolveRepoType'
3
+ import type { RepoType } from './resolveRepoType'
3
4
4
- export const editLinkPatternGithub = ':repo/edit/:branch/:path'
5
- export const editLinkPatternGitlab = ':repo/-/edit/:branch/:path'
6
- export const editLinkPatternBitbucket =
7
- ':repo/src/:branch/:path?mode=edit&spa=0&at=:branch&fileviewer=file-view-default'
5
+ export const editLinkPatterns : Record < Exclude < RepoType , null > , string > = {
6
+ GitHub : ':repo/edit/:branch/:path' ,
7
+ GitLab : ':repo/-/edit/:branch/:path' ,
8
+ Bitbucket :
9
+ ':repo/src/:branch/:path?mode=edit&spa=0&at=:branch&fileviewer=file-view-default' ,
10
+ }
8
11
9
12
export const resolveEditLink = ( {
10
13
docsRepo,
@@ -21,16 +24,12 @@ export const resolveEditLink = ({
21
24
} ) : string | null => {
22
25
const repoType = resolveRepoType ( docsRepo )
23
26
24
- let pattern : string | null = null
27
+ let pattern : string | undefined
25
28
26
29
if ( editLinkPattern ) {
27
30
pattern = editLinkPattern
28
- } else if ( repoType === 'GitHub' ) {
29
- pattern = editLinkPatternGithub
30
- } else if ( repoType === 'GitLab' ) {
31
- pattern = editLinkPatternGitlab
32
- } else if ( repoType === 'Bitbucket' ) {
33
- pattern = editLinkPatternBitbucket
31
+ } else if ( repoType !== null ) {
32
+ pattern = editLinkPatterns [ repoType ]
34
33
}
35
34
36
35
if ( ! pattern ) return null
0 commit comments