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 @@