From d4938bc28a0ad904bf38f875b57a595ed7c14c68 Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 6 Sep 2024 18:14:59 +0200 Subject: [PATCH 01/13] feat: add repository and link for external translations --- __tests__/e2e/.vitepress/config.ts | 8 ++++ .../theme-default/components/VPMenuLink.vue | 4 ++ .../components/VPNavBarTranslations.vue | 25 ++++++++++++- .../components/VPNavScreenTranslations.vue | 2 + src/client/theme-default/composables/langs.ts | 37 ++++++++++++++++--- types/shared.d.ts | 11 +++++- 6 files changed, 78 insertions(+), 9 deletions(-) diff --git a/__tests__/e2e/.vitepress/config.ts b/__tests__/e2e/.vitepress/config.ts index 65f845ab364d..45b9b2d1480b 100644 --- a/__tests__/e2e/.vitepress/config.ts +++ b/__tests__/e2e/.vitepress/config.ts @@ -159,6 +159,14 @@ export default defineConfig({ lazyLoading: true } }, + locales: { + root: { label: 'English', repo: 'https://github.com/vuejs/vitepress' }, + zh: { + label: '简体中文', + link: 'https://vitepress.dev/zh/', + repo: 'https://github.com/vitejs/vite' + } + }, themeConfig: { nav, sidebar, diff --git a/src/client/theme-default/components/VPMenuLink.vue b/src/client/theme-default/components/VPMenuLink.vue index 52b4fac38ea0..4effdcbac8b6 100644 --- a/src/client/theme-default/components/VPMenuLink.vue +++ b/src/client/theme-default/components/VPMenuLink.vue @@ -8,6 +8,10 @@ defineProps<{ item: DefaultTheme.NavItemWithLink }>() +defineSlots<{ + default: () => void +}>() + const { page } = useData() diff --git a/src/client/theme-default/components/VPNavBarTranslations.vue b/src/client/theme-default/components/VPNavBarTranslations.vue index a92aad8c9a46..15e225f6dc75 100644 --- a/src/client/theme-default/components/VPNavBarTranslations.vue +++ b/src/client/theme-default/components/VPNavBarTranslations.vue @@ -3,9 +3,13 @@ import VPFlyout from './VPFlyout.vue' import VPMenuLink from './VPMenuLink.vue' import { useData } from '../composables/data' import { useLangs } from '../composables/langs' +import VPSocialLink from "./VPSocialLink.vue"; +// import { computed } from 'vue' const { theme } = useData() const { localeLinks, currentLang } = useLangs({ correspondingLink: true }) +// for helping translate +// const repoLink = computed(() => currentLang.value.repo || (localeLinks.value.length > 1 && localeLinks.value.some(l => !!l.repo))) @@ -48,7 +48,7 @@ function toggle() { {{ locale.text }} diff --git a/src/client/theme-default/composables/langs.ts b/src/client/theme-default/composables/langs.ts index 18d3e88bae8b..7996e10742f4 100644 --- a/src/client/theme-default/composables/langs.ts +++ b/src/client/theme-default/composables/langs.ts @@ -8,16 +8,11 @@ export function useLangs({ correspondingLink = false } = {}) { const lang = site.value.locales[localeIndex.value] return { label: lang?.label, + repository: lang?.repository, link: lang?.link || localeIndex.value === 'root' ? '/' - : `/${localeIndex.value}/`, - repository: lang?.repository - ? { - link: lang.repository.link, - title: lang.repository.title - } - : undefined + : `/${localeIndex.value}/` } }) @@ -27,12 +22,7 @@ export function useLangs({ correspondingLink = false } = {}) { ? [] : { text: value.label, - repository: value.repository - ? { - link: value.repository.link, - title: value.repository.title - } - : undefined, + repository: value.repository, link: normalizeLink( value.link || (key === 'root' ? '/' : `/${key}/`), diff --git a/src/client/theme-default/styles/icons.css b/src/client/theme-default/styles/icons.css index b5612d1f8192..a8a789a14a77 100644 --- a/src/client/theme-default/styles/icons.css +++ b/src/client/theme-default/styles/icons.css @@ -121,3 +121,11 @@ .vpi-social-youtube { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z'/%3E%3C/svg%3E"); } +/* gitlab: under MIT from https://icon-sets.iconify.design/akar-icons/gitlab-fill/ */ +.vpi-repo-gitlab { + --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='m22.749 9.769l-.031-.08l-3.027-7.9a.79.79 0 0 0-.782-.495a.8.8 0 0 0-.456.17a.8.8 0 0 0-.268.408L16.14 8.125H7.865L5.822 1.872a.8.8 0 0 0-.269-.409a.81.81 0 0 0-.926-.05c-.14.09-.25.22-.312.376L1.283 9.684l-.03.08a5.62 5.62 0 0 0 1.864 6.496l.01.008l.028.02l4.61 3.453l2.282 1.726l1.39 1.049a.935.935 0 0 0 1.13 0l1.389-1.05l2.281-1.726l4.639-3.473l.011-.01A5.62 5.62 0 0 0 22.75 9.77'/%3E%3C/svg%3E"); +} +/* bitbucket: under MIT from https://icon-sets.iconify.design/pajamas/bitbucket/ */ +.vpi-repo-bitbucket { + --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23000' d='M1.454 1.816a.45.45 0 0 0-.345.153a.44.44 0 0 0-.103.358L2.91 13.684c.049.287.3.498.596.5h9.135a.45.45 0 0 0 .449-.37L14.994 2.33a.44.44 0 0 0-.1-.358a.45.45 0 0 0-.342-.156zm8.018 8.208H6.557l-.79-4.05h4.412z'/%3E%3C/svg%3E"); +} diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 37be5babd03c..5d9268f746eb 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -334,9 +334,11 @@ export namespace DefaultTheme { } export type SocialLinkIcon = + | 'bitbucket' | 'discord' | 'facebook' | 'github' + | 'gitlab' | 'instagram' | 'linkedin' | 'mastodon' diff --git a/types/shared.d.ts b/types/shared.d.ts index 09449edd1867..1f4604c8ea61 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -159,6 +159,8 @@ export interface LocaleSpecificConfig { themeConfig?: ThemeConfig } +export type RepositoryLinkIcon = 'github' | 'gitlab' | 'bitbucket' + export type LocaleConfig = Record< string, LocaleSpecificConfig & { @@ -167,6 +169,8 @@ export type LocaleConfig = Record< repository?: { link: string title: string + /** @default 'github' */ + icon?: RepositoryLinkIcon help?: { link: string text: string From 95900ad606ba2799b007d45185edc85f464aeffa Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 6 Sep 2024 23:51:36 +0200 Subject: [PATCH 12/13] chore: update computed repo in nv screen sfc --- src/client/theme-default/components/VPNavScreenTranslations.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/theme-default/components/VPNavScreenTranslations.vue b/src/client/theme-default/components/VPNavScreenTranslations.vue index 23944b33446b..79dedc01095a 100644 --- a/src/client/theme-default/components/VPNavScreenTranslations.vue +++ b/src/client/theme-default/components/VPNavScreenTranslations.vue @@ -6,7 +6,7 @@ import VPSocialLink from "./VPSocialLink.vue"; const { localeLinks, currentLang } = useLangs({ correspondingLink: true }) const isOpen = ref(false) -const repo = computed(() => !!currentLang.value.repository || (localeLinks.value.length > 1 && localeLinks.value.some(l => !!l.repository))) +const repo = computed(() => !!currentLang.value.repository || localeLinks.value.some(l => !!l.repository)) function toggle() { isOpen.value = !isOpen.value From bb76458c7d050dbaee06aa171947158c97351536 Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 7 Sep 2024 00:33:41 +0200 Subject: [PATCH 13/13] chore: update `gitlab` and `bitbacket` css class name --- src/client/theme-default/styles/icons.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/theme-default/styles/icons.css b/src/client/theme-default/styles/icons.css index a8a789a14a77..40bf7267b92b 100644 --- a/src/client/theme-default/styles/icons.css +++ b/src/client/theme-default/styles/icons.css @@ -122,10 +122,10 @@ --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z'/%3E%3C/svg%3E"); } /* gitlab: under MIT from https://icon-sets.iconify.design/akar-icons/gitlab-fill/ */ -.vpi-repo-gitlab { +.vpi-social-gitlab { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='m22.749 9.769l-.031-.08l-3.027-7.9a.79.79 0 0 0-.782-.495a.8.8 0 0 0-.456.17a.8.8 0 0 0-.268.408L16.14 8.125H7.865L5.822 1.872a.8.8 0 0 0-.269-.409a.81.81 0 0 0-.926-.05c-.14.09-.25.22-.312.376L1.283 9.684l-.03.08a5.62 5.62 0 0 0 1.864 6.496l.01.008l.028.02l4.61 3.453l2.282 1.726l1.39 1.049a.935.935 0 0 0 1.13 0l1.389-1.05l2.281-1.726l4.639-3.473l.011-.01A5.62 5.62 0 0 0 22.75 9.77'/%3E%3C/svg%3E"); } /* bitbucket: under MIT from https://icon-sets.iconify.design/pajamas/bitbucket/ */ -.vpi-repo-bitbucket { +.vpi-social-bitbucket { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23000' d='M1.454 1.816a.45.45 0 0 0-.345.153a.44.44 0 0 0-.103.358L2.91 13.684c.049.287.3.498.596.5h9.135a.45.45 0 0 0 .449-.37L14.994 2.33a.44.44 0 0 0-.1-.358a.45.45 0 0 0-.342-.156zm8.018 8.208H6.557l-.79-4.05h4.412z'/%3E%3C/svg%3E"); }