From ed291fc4266df9fd5cbc052167e37a726aa8ad96 Mon Sep 17 00:00:00 2001 From: Percy Ma Date: Thu, 2 Jun 2022 18:04:07 +0800 Subject: [PATCH] fix: unable to use non-GitHub repo in editLink close https://github.com/vuejs/vitepress/issues/694 --- docs/config/theme-configs.md | 55 +++++++++++++++++++ .../theme-default/composables/edit-link.ts | 2 +- types/default-theme.d.ts | 7 +++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/config/theme-configs.md b/docs/config/theme-configs.md index 17c24708849c..7755d5ee25eb 100644 --- a/docs/config/theme-configs.md +++ b/docs/config/theme-configs.md @@ -188,6 +188,61 @@ export interface Footer { } ``` +## editLink + +- Type: `EditLink` + +Edit link configuration. You can then customize git repo link and display text. + +```ts +export default { + themeConfig: { + editLink: { + domain: 'github.com' + repo: 'vuejs/vitepress', + branch: 'next', + dir: 'docs', + text: 'Edit this page on GitHub' + }, + } +} +``` + +```ts +export interface EditLink { + /** + * Domain of git repo + * + * @example 'github.com' or 'https://github.com' + */ + domain?: string + /** + * Repo of the site. + * + * @example 'vuejs/docs' + */ + repo: string + /** + * Branch of the repo. + * + * @default 'main' + */ + branch?: string + /** + * If your docs are not at the root of the repo. + * + * @example 'docs' + */ + dir?: string + /** + * Custom text for edit link. + * + * @default 'Edit this page' + */ + text?: string +} +``` + ## lastUpdatedText - Type: `string` diff --git a/src/client/theme-default/composables/edit-link.ts b/src/client/theme-default/composables/edit-link.ts index 32bf66c20cff..44dd571343e3 100644 --- a/src/client/theme-default/composables/edit-link.ts +++ b/src/client/theme-default/composables/edit-link.ts @@ -6,7 +6,7 @@ export function useEditLink() { return computed(() => { const url = [ - 'https://github.com', + `https://${theme.value.editLink?.domain || 'github.com'}`, theme.value.editLink?.repo || '???', 'edit', theme.value.editLink?.branch || 'main', diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 2f44cd113774..6ed2a0047dab 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -119,6 +119,13 @@ export namespace DefaultTheme { // edit link ----------------------------------------------------------------- export interface EditLink { + /** + * Domain of git repo + * + * @example 'github.com' or 'https://github.com' + */ + domain?: string + /** * Repo of the site. *