diff --git a/README.md b/README.md index 49717736..b3b58992 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ home: true ### Localising news articles To localize a news article, just add a file with the same name to the -corresponding language folder such as `/content/zh/`, i.e.: +corresponding language folder such as `/content/zh-cn/`, i.e.: ``` -/content/zh/news/2024-09-18-aosc-os-relnote.md +/content/zh-cn/news/2024-09-18-aosc-os-relnote.md ``` diff --git a/components/CategoryList.vue b/components/CategoryList.vue index 0fd866a7..1d8be2cc 100644 --- a/components/CategoryList.vue +++ b/components/CategoryList.vue @@ -9,11 +9,13 @@ const props = defineProps<{ }>(); const { data, error, status } = await useAsyncData( - computed( - () => - `${locale.value}:CategoryList:${props.category}:${props.limit}:${props.filters?.map((obj) => `${obj.key}-${obj.value}`).join('--')}` - ), - queryCollectionCategory(props.category, props.limit, props.filters) + `${locale.value}:CategoryList:${props.category}:${props.limit}:${props.filters?.map((obj) => `${obj.key}-${obj.value}`).join('--')}`, + queryCollectionCategory( + locale.value, + props.category, + props.limit, + props.filters + ) ); diff --git a/components/CommonContent.vue b/components/CommonContent.vue index 34ba141e..cf168b5b 100644 --- a/components/CommonContent.vue +++ b/components/CommonContent.vue @@ -1,6 +1,7 @@ diff --git a/public/heading/portal-logo-typed.en.svg b/public/heading/portal-logo-typed.en-us.svg similarity index 100% rename from public/heading/portal-logo-typed.en.svg rename to public/heading/portal-logo-typed.en-us.svg diff --git a/public/heading/portal-logo-typed.zh.svg b/public/heading/portal-logo-typed.zh-cn.svg similarity index 100% rename from public/heading/portal-logo-typed.zh.svg rename to public/heading/portal-logo-typed.zh-cn.svg diff --git a/public/heading/portal-logo.en.svg b/public/heading/portal-logo.en-us.svg similarity index 100% rename from public/heading/portal-logo.en.svg rename to public/heading/portal-logo.en-us.svg diff --git a/public/heading/portal-logo.zh.svg b/public/heading/portal-logo.zh-cn.svg similarity index 100% rename from public/heading/portal-logo.zh.svg rename to public/heading/portal-logo.zh-cn.svg diff --git a/utils/content.ts b/utils/content.ts index 43c76ca8..94472d54 100644 --- a/utils/content.ts +++ b/utils/content.ts @@ -1,23 +1,17 @@ -import type { - CollectionQueryBuilder, - EnCollectionItem, - ZhCollectionItem -} from '@nuxt/content'; +import { type NuxtI18nCode, i18nCodeToContent } from '~/i18n/config'; + +export const queryCollectionLocale = (locale: NuxtI18nCode) => + queryCollection(i18nCodeToContent(locale)); export const queryCollectionCategory = ( + locale: NuxtI18nCode, category?: string, limit: number = 0, filters?: Array<{ key: string; value: string }> ) => { - const { locale } = useI18n(); - - let q = ( - queryCollection(locale.value) as CollectionQueryBuilder< - ZhCollectionItem | EnCollectionItem - > - ) + let q = queryCollectionLocale(locale) .select('path', 'title', 'date') - .where('path', 'LIKE', `/${category}%`) + .where('path', 'LIKE', `/${category || ''}%`) .order('date', 'DESC') .limit(limit); diff --git a/utils/utils.js b/utils/utils.js index ef9f08d1..0943943e 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -9,13 +9,13 @@ export const BToMB = (byteSize, fixed = 3) => { export const copyToClipboard = (locale, text, name = '') => { const lang = (() => { switch (locale) { - case 'zh': + case 'zh-cn': return { copy: '复制', success: '成功', failure: '失败' }; - case 'en': + case 'en-us': return { copy: 'copy', success: 'success',