diff --git a/src/client/theme-default/composables/edit-link.ts b/src/client/theme-default/composables/edit-link.ts index d3e80086..a42f3ecc 100644 --- a/src/client/theme-default/composables/edit-link.ts +++ b/src/client/theme-default/composables/edit-link.ts @@ -10,10 +10,11 @@ const editLinkPatterns = { } function resolveRepoType(repo: string) { + if (/github\.com/.test(repo)) return 'GitHub' if (/bitbucket\.org/.test(repo)) return 'Bitbucket' if (/gitlab\.com/.test(repo)) return 'GitLab' if (/gitee\.com/.test(repo)) return 'Gitee' - return 'GitHub' + return null } export function useEditLink() { @@ -21,16 +22,19 @@ export function useEditLink() { return computed(() => { const { - repo = '???', + repo = '', branch = 'main', dir = '', - text = 'Edit this page' + text = 'Edit this page', + pattern = '' } = theme.value.editLink || {} const { relativePath } = page.value const base = /:\/\//.test(repo) ? repo : `https://github.com/${repo}` - const pattern = editLinkPatterns[resolveRepoType(base)] - const url = pattern + const type = resolveRepoType(base) + const urlPattern = pattern || !type ? pattern : editLinkPatterns[type] + + const url = urlPattern .replace(/:repo/g, base) .replace(/:branch/g, branch) .replace(/:path/g, `${dir}/${relativePath}`) diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 2f44cd11..6118d3da 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -146,6 +146,13 @@ export namespace DefaultTheme { * @default 'Edit this page' */ text?: string + + /** + * Custom pattern for edit link. + * + * @example ':repo/-/edit/:branch/:path' + */ + pattern?: string } // social link ---------------------------------------------------------------