simple-content-site 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Collections, FooterCollectionItem } from '@nuxt/content'
|
|
2
|
+
import { useSiteI18n } from './useSiteI18n'
|
|
2
3
|
|
|
3
4
|
export const useSiteFooter = () => {
|
|
4
|
-
const { locale, isEnabled } = useSiteI18n()
|
|
5
|
-
const defaultLocale = useRuntimeConfig().public.i18n.defaultLocale!
|
|
5
|
+
const { locale, isEnabled, defaultLocale } = useSiteI18n()
|
|
6
6
|
const collectionName = computed(() => isEnabled.value ? `footer_${locale.value}` : 'footer')
|
|
7
7
|
|
|
8
8
|
return useAsyncData(collectionName, async () => {
|
|
9
9
|
const customFooter = await queryCollection(collectionName.value as keyof Collections).first()
|
|
10
10
|
if (!customFooter) {
|
|
11
11
|
// attempt to find for the default language
|
|
12
|
-
if (isEnabled.value) {
|
|
13
|
-
const fallbackFooter = await queryCollection(`footer_${defaultLocale}` as keyof Collections).first()
|
|
12
|
+
if (isEnabled.value && defaultLocale.value) {
|
|
13
|
+
const fallbackFooter = await queryCollection(`footer_${defaultLocale.value}` as keyof Collections).first()
|
|
14
14
|
if (fallbackFooter) {
|
|
15
15
|
return fallbackFooter as FooterCollectionItem
|
|
16
16
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Collections, HeaderCollectionItem } from '@nuxt/content'
|
|
2
|
+
import { useSiteI18n } from './useSiteI18n'
|
|
2
3
|
|
|
3
4
|
export const useSiteHeader = () => {
|
|
4
5
|
const config = useAppConfig()
|
|
5
|
-
const { locale, isEnabled } = useSiteI18n()
|
|
6
|
-
const defaultLocale = useRuntimeConfig().public.i18n.defaultLocale!
|
|
6
|
+
const { locale, isEnabled, defaultLocale } = useSiteI18n()
|
|
7
7
|
const collectionName = computed(() => isEnabled.value ? `header_${locale.value}` : 'header')
|
|
8
8
|
|
|
9
9
|
return useAsyncData(collectionName, async () => {
|
|
10
10
|
const customHeader = await queryCollection(collectionName.value as keyof Collections).first()
|
|
11
11
|
if (!customHeader) {
|
|
12
|
-
if (isEnabled.value) {
|
|
13
|
-
const fallbackHeader = await queryCollection(`header_${defaultLocale}` as keyof Collections).first()
|
|
12
|
+
if (isEnabled.value && defaultLocale.value) {
|
|
13
|
+
const fallbackHeader = await queryCollection(`header_${defaultLocale.value}` as keyof Collections).first()
|
|
14
14
|
if (fallbackHeader) {
|
|
15
15
|
return fallbackHeader as HeaderCollectionItem
|
|
16
16
|
}
|
|
@@ -3,12 +3,13 @@ import en from '../../i18n/locales/en.json'
|
|
|
3
3
|
|
|
4
4
|
export const useSiteI18n = () => {
|
|
5
5
|
const config = useRuntimeConfig().public
|
|
6
|
-
const isEnabled = ref(!!config.i18n)
|
|
6
|
+
const isEnabled = ref(!!config.i18n && config.i18n.locales?.length > 0)
|
|
7
7
|
|
|
8
8
|
if (!isEnabled.value) {
|
|
9
9
|
return {
|
|
10
10
|
isEnabled,
|
|
11
11
|
locale: ref('en'),
|
|
12
|
+
defaultLocale: ref('en'),
|
|
12
13
|
locales: [],
|
|
13
14
|
localePath: (path: string) => path,
|
|
14
15
|
switchLocalePath: () => {},
|
|
@@ -25,6 +26,7 @@ export const useSiteI18n = () => {
|
|
|
25
26
|
return {
|
|
26
27
|
isEnabled,
|
|
27
28
|
locale,
|
|
29
|
+
defaultLocale: ref(config.i18n.defaultLocale || 'en'),
|
|
28
30
|
locales: filteredLocales,
|
|
29
31
|
t,
|
|
30
32
|
localePath: useLocalePath(),
|
|
@@ -9,10 +9,18 @@ definePageMeta({
|
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
const route = useRoute()
|
|
12
|
-
const { locale, isEnabled } = useSiteI18n()
|
|
12
|
+
const { locale, isEnabled, defaultLocale } = useSiteI18n()
|
|
13
13
|
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
|
|
14
14
|
|
|
15
|
-
const collectionName = computed(() =>
|
|
15
|
+
const collectionName = computed(() => {
|
|
16
|
+
console.log('isEnabled', isEnabled.value)
|
|
17
|
+
console.log('defaultLocale', defaultLocale.value)
|
|
18
|
+
console.log('locale', locale.value)
|
|
19
|
+
if (!isEnabled.value || !defaultLocale.value) {
|
|
20
|
+
return 'pages'
|
|
21
|
+
}
|
|
22
|
+
return `pages_${locale.value}`
|
|
23
|
+
})
|
|
16
24
|
|
|
17
25
|
const [{ data: page }] = await Promise.all([
|
|
18
26
|
useAsyncData(kebabCase(route.path), () => queryCollection(collectionName.value as keyof Collections).path(route.path).first() as Promise<PagesCollectionItem>),
|
package/app/plugins/i18n.ts
CHANGED