Compare commits

...

2 commits

Author SHA1 Message Date
CDN
48b65d804a
fix: map language code in updates
All checks were successful
Deploy / Deploy (push) Successful in 1m24s
2025-02-03 23:09:11 +08:00
CDN
01e69e4f5b
chore: update dir structure in README 2025-02-03 22:56:36 +08:00
5 changed files with 32 additions and 18 deletions

View file

@ -35,9 +35,9 @@ Visit: [https://mirror.starset.fans](https://mirror.starset.fans)
```
homepage
├── data/ # Content files
│ ├── zh-CN/ # Simplified Chinese data
│ ├── zh-TW/ # Traditional Chinese data
│ └── en-US/ # English data
│ ├── zh-Hans/ # Simplified Chinese data
│ ├── zh-Hant/ # Traditional Chinese data
│ └── en/ # English data
├── src/ # Source code
├── public/ # Static assets
├── docs/ # Documentation

View file

@ -35,9 +35,9 @@ pnpm build
```
homepage
├── data/ # 内容文件
│ ├── zh-CN/ # 简体中文数据
│ ├── zh-TW/ # 繁体中文数据
│ └── en-US/ # 英文数据
│ ├── zh-Hans/ # 简体中文数据
│ ├── zh-Hant/ # 繁体中文数据
│ └── en/ # 英文数据
├── src/ # 源代码
├── public/ # 静态资源
├── docs/ # 文档

View file

@ -35,9 +35,9 @@ pnpm build
```
homepage
├── data/ # 內容文件
│ ├── zh-CN/ # 簡體中文資料
│ ├── zh-TW/ # 繁體中文資料
│ └── en-US/ # 英文資料
│ ├── zh-Hans/ # 簡體中文資料
│ ├── zh-Hant/ # 繁體中文資料
│ └── en/ # 英文資料
├── src/ # 原始碼
├── public/ # 靜態資源
├── docs/ # 文件

View file

@ -216,7 +216,8 @@ const Timeline = () => {
</>
) : (
<div className="text-center py-20">
<p>{t('updates.notFound.title')}</p>
<p className="text-gray-900 dark:text-gray-100">{t('updates.notFound.title')}</p>
<p className="text-gray-600 dark:text-gray-400 mt-2">{t('updates.notFound.description')}</p>
</div>
)}
</div>

View file

@ -18,19 +18,28 @@ interface UpdatesIndex {
years: string[];
}
// Map i18n language codes to data directory paths
const LANGUAGE_CODE_MAP: Record<string, string> = {
'zh-CN': 'zh-Hans',
'zh-TW': 'zh-Hant',
'en': 'en',
'en-US': 'en'
};
// 获取更新年份列表
const getUpdateYears = async (language: string): Promise<string[]> => {
try {
const response = await fetch(`/data/${language}/updates.json`);
// Map the language code to the correct data directory path
const dataLanguage = LANGUAGE_CODE_MAP[language] || language;
const response = await fetch(`/data/${dataLanguage}/updates.json`);
if (!response.ok) {
throw new Error(`Failed to load updates index, status: ${response.status}`);
}
const index: UpdatesIndex = await response.json();
return index.years || [];
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn(`Failed to load updates index:`, error);
}
console.warn(`Failed to load updates index:`, error);
return [];
}
};
@ -38,16 +47,17 @@ const getUpdateYears = async (language: string): Promise<string[]> => {
// 动态获取指定的年度更新
const getYearUpdates = async (yearFile: string, language: string): Promise<YearUpdates | null> => {
try {
const response = await fetch(`/data/${language}/updates/${yearFile}`);
// Map the language code to the correct data directory path
const dataLanguage = LANGUAGE_CODE_MAP[language] || language;
const response = await fetch(`/data/${dataLanguage}/updates/${yearFile}`);
if (!response.ok) {
throw new Error(`Failed to load updates from ${yearFile}, status: ${response.status}`);
}
const data: YearUpdates = await response.json();
return data;
} catch (error) {
if (process.env.NODE_ENV === 'development') {
console.warn(`Failed to load updates from ${yearFile}:`, error);
}
console.warn(`Failed to load updates from ${yearFile}:`, error);
return null;
}
};
@ -85,6 +95,9 @@ export const useUpdates = (page: number = 1, pageSize: number = 10) => {
const { data: allUpdates = [], isLoading, error } = useQuery({
queryKey: ['updates', i18n.language],
queryFn: () => getAllUpdates(i18n.language),
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
retry: 3, // Retry failed requests up to 3 times
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000), // Exponential backoff
});
const getPaginatedUpdates = (selectedTags: string[] = []) => {