From efe0b21753afecbe29dd253df11a7f65ba5323f1 Mon Sep 17 00:00:00 2001 From: cdn0x12 Date: Mon, 3 Feb 2025 20:24:16 +0800 Subject: [PATCH 1/5] fix: update detailes does not load --- data/en-US/index.json | 1 + data/zh-CN/index.json | 1 + data/zh-TW/index.json | 1 + src/pages/UpdateDetailPage.tsx | 48 +++++++++++++++++++++++++++++----- src/utils/updates.ts | 6 +++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/data/en-US/index.json b/data/en-US/index.json index 2a97f1f..15f102d 100644 --- a/data/en-US/index.json +++ b/data/en-US/index.json @@ -63,6 +63,7 @@ "tags": { "journal": "Journal/Summary", "milestone": "Milestone", + "service": "Service", "other": "Other" }, "notFound": { diff --git a/data/zh-CN/index.json b/data/zh-CN/index.json index c00c550..9704145 100644 --- a/data/zh-CN/index.json +++ b/data/zh-CN/index.json @@ -84,6 +84,7 @@ "tags": { "journal": "日志/总结", "milestone": "里程碑", + "service": "服务", "other": "其它" }, "notFound": { diff --git a/data/zh-TW/index.json b/data/zh-TW/index.json index 190a33f..ac1a937 100644 --- a/data/zh-TW/index.json +++ b/data/zh-TW/index.json @@ -76,6 +76,7 @@ "tags": { "journal": "日誌/總結", "milestone": "里程碑", + "service": "服務", "other": "其他" }, "notFound": { diff --git a/src/pages/UpdateDetailPage.tsx b/src/pages/UpdateDetailPage.tsx index 2a8d26c..5d7c2cf 100644 --- a/src/pages/UpdateDetailPage.tsx +++ b/src/pages/UpdateDetailPage.tsx @@ -8,25 +8,31 @@ import { useUpdates, Update } from '../utils/updates'; const UpdateDetailPage: React.FC = () => { const { id } = useParams<{ id: string }>(); const { i18n, t } = useTranslation(); - const { getAllUpdates } = useUpdates(); + const { data: allUpdates = [], isLoading } = useUpdates(); const [update, setUpdate] = useState(null); const [content, setContent] = useState(null); useEffect(() => { + console.log(`[Debug] UpdateDetailPage - Effect triggered with id: ${id}`); + console.log(`[Debug] Current language: ${i18n.language}`); + console.log(`[Debug] Loading status: ${isLoading}`); + console.log(`[Debug] Available updates:`, allUpdates); + const fetchUpdateData = async () => { if (!id) { + console.log('[Debug] No id provided, clearing update and content'); setUpdate(null); setContent(null); return; } try { - // 获取所有更新条目 - const allUpdates = await getAllUpdates(); // 查找对应 id 的更新条目 const foundUpdate = allUpdates.find(u => u.id === id); + console.log(`[Debug] Found update for id ${id}:`, foundUpdate); if (!foundUpdate) { + console.log(`[Debug] Update not found for id: ${id}`); setUpdate(null); setContent(null); return; @@ -36,38 +42,66 @@ const UpdateDetailPage: React.FC = () => { // 如果该更新有 link 属性,则说明为外链,详情页不需要加载内容 if (foundUpdate.link) { + console.log(`[Debug] Update is an external link: ${foundUpdate.link}`); setContent(null); return; } // 从日期中提取年份 const year = new Date(foundUpdate.date).getFullYear(); + console.log(`[Debug] Loading content for year: ${year}`); try { // 尝试加载 Markdown 文件 const mdPath = `/data/${i18n.language}/updates/${year}/${foundUpdate.id}.md`; + console.log(`[Debug] Attempting to load markdown from: ${mdPath}`); const response = await fetch(mdPath); - if (!response.ok) { - throw new Error('Markdown file not found'); + // 检查响应状态和内容类型 + const contentType = response.headers.get('content-type'); + console.log(`[Debug] Response content type: ${contentType}`); + + if (!response.ok || !contentType || !contentType.includes('text/markdown')) { + console.log(`[Debug] Markdown file not found or invalid content type at: ${mdPath}`); + throw new Error('Markdown file not found or invalid'); } const mdText = await response.text(); + // 简单验证内容是否看起来像 markdown + if (mdText.includes(' +
+

+ {t('common.loading')} +

+
+ + ); + } if (!update) { return ( diff --git a/src/utils/updates.ts b/src/utils/updates.ts index b292fb6..efc402c 100644 --- a/src/utils/updates.ts +++ b/src/utils/updates.ts @@ -20,12 +20,14 @@ interface UpdatesIndex { // 获取更新年份列表 const getUpdateYears = async (language: string): Promise => { + console.log(`[Debug] Fetching update years for language: ${language}`); try { const response = await fetch(`/data/${language}/updates.json`); if (!response.ok) { throw new Error(`Failed to load updates index, status: ${response.status}`); } const index: UpdatesIndex = await response.json(); + console.log(`[Debug] Found years:`, index.years); return index.years || []; } catch (error) { if (process.env.NODE_ENV === 'development') { @@ -37,12 +39,14 @@ const getUpdateYears = async (language: string): Promise => { // 动态获取指定的年度更新 const getYearUpdates = async (yearFile: string, language: string): Promise => { + console.log(`[Debug] Fetching updates for year file: ${yearFile}, language: ${language}`); try { const response = await fetch(`/data/${language}/updates/${yearFile}`); if (!response.ok) { throw new Error(`Failed to load updates from ${yearFile}, status: ${response.status}`); } const data: YearUpdates = await response.json(); + console.log(`[Debug] Loaded updates for ${yearFile}:`, data.updates?.length || 0, 'updates'); return data; } catch (error) { if (process.env.NODE_ENV === 'development') { @@ -54,6 +58,7 @@ const getYearUpdates = async (yearFile: string, language: string): Promise => { + console.log(`[Debug] Getting all updates for language: ${language}, selectedTags:`, selectedTags); const allUpdates: Update[] = []; // 从索引文件获取年份列表 @@ -131,6 +136,7 @@ export const useUpdates = (page: number = 1, pageSize: number = 10) => { return { getPaginatedUpdates, + data: allUpdates, isLoading, error }; From 23397634f1d14196bf87ac33e461ec981dc3c1de Mon Sep 17 00:00:00 2001 From: cdn0x12 Date: Mon, 3 Feb 2025 20:30:56 +0800 Subject: [PATCH 2/5] chore: update footer --- data/en-US/index.json | 2 +- data/zh-CN/index.json | 2 +- data/zh-TW/index.json | 2 +- src/App.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/en-US/index.json b/data/en-US/index.json index 15f102d..1bbeba5 100644 --- a/data/en-US/index.json +++ b/data/en-US/index.json @@ -124,7 +124,7 @@ "system": "System" }, "footer": { - "copyright": " 2024 STARSET Mirror." + "copyright": " 2020-{{currentYear}} STARSET Mirror." }, "social": { "links": [ diff --git a/data/zh-CN/index.json b/data/zh-CN/index.json index 9704145..ce86c7a 100644 --- a/data/zh-CN/index.json +++ b/data/zh-CN/index.json @@ -124,7 +124,7 @@ "system": "跟随系统" }, "footer": { - "copyright": " 2024 STARSET Mirror." + "copyright": " 2020-{{currentYear}} STARSET Mirror." }, "social": { "links": [ diff --git a/data/zh-TW/index.json b/data/zh-TW/index.json index ac1a937..58dda60 100644 --- a/data/zh-TW/index.json +++ b/data/zh-TW/index.json @@ -108,7 +108,7 @@ "system": "跟隨系統" }, "footer": { - "copyright": " 2024 STARSET Mirror." + "copyright": " 2020-{{currentYear}} STARSET Mirror." }, "social": { "links": [ diff --git a/src/App.tsx b/src/App.tsx index d1db8a3..be26e65 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -78,7 +78,7 @@ function App() {