From 84e85b25184f7628de97a33b32e1384a70351830 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 9 Sep 2022 10:21:37 +0530 Subject: [PATCH 01/24] merge feat-i18n fix: don't break when locales are not used fix: make navbar title link to current locale feat: allow customizing locale link in navbar feat: allow overriding theme config feat: support overriding head based on current locale feat: support customizing title and description feat: add lang attribute to html based on route feat: show current and available langs on navbar fix: refactor types to support locales fix: group label customization to theme.translations --- src/client/app/data.ts | 18 +-- src/client/app/utils.ts | 2 +- src/client/index.ts | 3 +- .../components/VPAlgoliaSearchBox.vue | 8 +- .../theme-default/components/VPCarbonAds.vue | 9 +- .../theme-default/components/VPDocAside.vue | 2 +- .../components/VPDocAsideCarbonAds.vue | 7 +- .../components/VPDocAsideOutline.vue | 2 +- .../theme-default/components/VPDocFooter.vue | 4 +- .../components/VPDocFooterLastUpdated.vue | 2 +- .../theme-default/components/VPLocalNav.vue | 8 +- .../components/VPNavBarExtra.vue | 12 +- .../components/VPNavBarSearch.vue | 2 +- .../components/VPNavBarTitle.vue | 7 +- .../components/VPNavBarTranslations.vue | 10 +- .../components/VPNavScreenAppearance.vue | 6 +- .../components/VPNavScreenTranslations.vue | 15 +- .../theme-default/composables/edit-link.ts | 2 +- src/client/theme-default/composables/langs.ts | 32 +++++ src/client/theme-default/composables/nav.ts | 36 +---- src/client/theme-default/support/sidebar.ts | 2 +- src/client/theme-default/support/utils.ts | 45 +----- src/node/build/render.ts | 5 +- src/node/config.ts | 38 +++-- src/node/index.ts | 1 - src/node/markdown/markdown.ts | 5 +- src/shared/shared.ts | 131 ++++++++---------- types/default-theme.d.ts | 97 ++++++------- types/shared.d.ts | 51 ++----- 29 files changed, 243 insertions(+), 319 deletions(-) create mode 100644 src/client/theme-default/composables/langs.ts diff --git a/src/client/app/data.ts b/src/client/app/data.ts index 22dc314194ef..3d9508090c68 100644 --- a/src/client/app/data.ts +++ b/src/client/app/data.ts @@ -5,9 +5,9 @@ import { PageData, SiteData, resolveSiteDataByRoute, - createTitle + createTitle, + DefaultTheme } from '../shared.js' -import { withBase } from './utils.js' export const dataSymbol: InjectionKey = Symbol() @@ -19,7 +19,7 @@ export interface VitePressData { title: Ref description: Ref lang: Ref - localePath: Ref + localeIndex: Ref } // site data is a singleton @@ -39,7 +39,7 @@ if (import.meta.hot) { // per-app data export function initData(route: Route): VitePressData { const site = computed(() => - resolveSiteDataByRoute(siteDataRef.value, route.path) + resolveSiteDataByRoute(siteDataRef.value, route.data.relativePath) ) return { @@ -48,13 +48,7 @@ export function initData(route: Route): VitePressData { page: computed(() => route.data), frontmatter: computed(() => route.data.frontmatter), lang: computed(() => site.value.lang), - localePath: computed(() => { - const { langs, lang } = site.value - const path = Object.keys(langs).find( - (langPath) => langs[langPath].lang === lang - ) - return withBase(path || '/') - }), + localeIndex: computed(() => site.value.localeIndex || 'root'), title: computed(() => { return createTitle(site.value, route.data) }), @@ -64,7 +58,7 @@ export function initData(route: Route): VitePressData { } } -export function useData(): VitePressData { +export function useData(): VitePressData { const data = inject(dataSymbol) if (!data) { throw new Error('vitepress data not properly injected in app') diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 2bc3f28b14f9..2f8be606544a 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -1,7 +1,7 @@ import { siteDataRef } from './data.js' import { inBrowser, EXTERNAL_URL_RE } from '../shared.js' -export { inBrowser } +export { inBrowser } from '../shared.js' /** * Join two paths by resolving the slash collision. diff --git a/src/client/index.ts b/src/client/index.ts index 4d56c9ea3b94..1ed560d902a1 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -11,8 +11,7 @@ export type { PageData, SiteData, HeadConfig, - Header, - LocaleConfig + Header } from '../../types/shared.js' // composables diff --git a/src/client/theme-default/components/VPAlgoliaSearchBox.vue b/src/client/theme-default/components/VPAlgoliaSearchBox.vue index dce2916aee2e..08822b931156 100644 --- a/src/client/theme-default/components/VPAlgoliaSearchBox.vue +++ b/src/client/theme-default/components/VPAlgoliaSearchBox.vue @@ -4,12 +4,16 @@ import { default as docsearch } from '@docsearch/js' import { onMounted } from 'vue' import { useRouter, useRoute, useData } from 'vitepress' +const props = defineProps<{ + algolia: DefaultTheme.AlgoliaSearchOptions +}>() + const router = useRouter() const route = useRoute() -const { theme, site } = useData() +const { site } = useData() onMounted(() => { - initialize(theme.value.algolia) + initialize(props.algolia) setTimeout(poll, 16) }) diff --git a/src/client/theme-default/components/VPCarbonAds.vue b/src/client/theme-default/components/VPCarbonAds.vue index d1f669f18fd2..4da1508d43db 100644 --- a/src/client/theme-default/components/VPCarbonAds.vue +++ b/src/client/theme-default/components/VPCarbonAds.vue @@ -1,10 +1,13 @@