|
|
@ -10,10 +10,11 @@ const editLinkPatterns = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function resolveRepoType(repo: string) {
|
|
|
|
function resolveRepoType(repo: string) {
|
|
|
|
|
|
|
|
if (/github\.com/.test(repo)) return 'GitHub'
|
|
|
|
if (/bitbucket\.org/.test(repo)) return 'Bitbucket'
|
|
|
|
if (/bitbucket\.org/.test(repo)) return 'Bitbucket'
|
|
|
|
if (/gitlab\.com/.test(repo)) return 'GitLab'
|
|
|
|
if (/gitlab\.com/.test(repo)) return 'GitLab'
|
|
|
|
if (/gitee\.com/.test(repo)) return 'Gitee'
|
|
|
|
if (/gitee\.com/.test(repo)) return 'Gitee'
|
|
|
|
return 'GitHub'
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function useEditLink() {
|
|
|
|
export function useEditLink() {
|
|
|
@ -21,16 +22,19 @@ export function useEditLink() {
|
|
|
|
|
|
|
|
|
|
|
|
return computed(() => {
|
|
|
|
return computed(() => {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
repo = '???',
|
|
|
|
repo = '',
|
|
|
|
branch = 'main',
|
|
|
|
branch = 'main',
|
|
|
|
dir = '',
|
|
|
|
dir = '',
|
|
|
|
text = 'Edit this page'
|
|
|
|
text = 'Edit this page',
|
|
|
|
|
|
|
|
pattern = ''
|
|
|
|
} = theme.value.editLink || {}
|
|
|
|
} = theme.value.editLink || {}
|
|
|
|
const { relativePath } = page.value
|
|
|
|
const { relativePath } = page.value
|
|
|
|
|
|
|
|
|
|
|
|
const base = /:\/\//.test(repo) ? repo : `https://github.com/${repo}`
|
|
|
|
const base = /:\/\//.test(repo) ? repo : `https://github.com/${repo}`
|
|
|
|
const pattern = editLinkPatterns[resolveRepoType(base)]
|
|
|
|
const type = resolveRepoType(base)
|
|
|
|
const url = pattern
|
|
|
|
const urlPattern = pattern || !type ? pattern : editLinkPatterns[type]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const url = urlPattern
|
|
|
|
.replace(/:repo/g, base)
|
|
|
|
.replace(/:repo/g, base)
|
|
|
|
.replace(/:branch/g, branch)
|
|
|
|
.replace(/:branch/g, branch)
|
|
|
|
.replace(/:path/g, `${dir}/${relativePath}`)
|
|
|
|
.replace(/:path/g, `${dir}/${relativePath}`)
|
|
|
|