diff --git a/src/components/themes/ThemeSwitcher.tsx b/src/components/themes/ThemeSwitcher.tsx index c1c52b3..828f324 100644 --- a/src/components/themes/ThemeSwitcher.tsx +++ b/src/components/themes/ThemeSwitcher.tsx @@ -65,25 +65,30 @@ const themeMap: Record = { export default function ThemeSwitcher({ themeId, posts, currentArticle, ...props }: ThemeSwitcherProps) { // Normalize posts from Astro collection (data property) const normalizedPosts = posts?.map(p => { - if (p.data) { - return { - ...p, - ...p.data, - id: p.id || p.slug, - slug: p.slug || p.id, - content: p.body - }; - } - return p; + let postData = p.data ? { ...p, ...p.data } : { ...p }; + // Safety for Astro Date objects failing in React + if (postData.date && typeof postData.date !== 'string') postData.date = String(postData.date); + if (postData.updatedDate && typeof postData.updatedDate !== 'string') postData.updatedDate = String(postData.updatedDate); + + return { + ...postData, + id: p.id || p.slug || postData.id, + slug: p.slug || p.id || postData.slug, + content: p.body || postData.content + }; }); - const normalizedArticle = currentArticle?.data ? { - ...currentArticle, - ...currentArticle.data, - id: currentArticle.id || currentArticle.slug, - slug: currentArticle.slug || currentArticle.id, - content: currentArticle.body - } : currentArticle; + let normalizedArticle = currentArticle?.data ? { ...currentArticle, ...currentArticle.data } : currentArticle ? { ...currentArticle } : null; + if (normalizedArticle) { + if (normalizedArticle.date && typeof normalizedArticle.date !== 'string') normalizedArticle.date = String(normalizedArticle.date); + if (normalizedArticle.updatedDate && typeof normalizedArticle.updatedDate !== 'string') normalizedArticle.updatedDate = String(normalizedArticle.updatedDate); + normalizedArticle = { + ...normalizedArticle, + id: currentArticle?.id || currentArticle?.slug || normalizedArticle.id, + slug: currentArticle?.slug || currentArticle?.id || normalizedArticle.slug, + content: currentArticle?.body || normalizedArticle.content + }; + } const SelectedTheme = themeMap[themeId] || CyberTheme; return ;