From 544b4c4ae00d1e8286bf1703945900584134e398 Mon Sep 17 00:00:00 2001 From: Daniel LaForce Date: Wed, 23 Apr 2025 14:56:51 -0600 Subject: [PATCH] fix: Add safe date handling and content rendering to dynamic routes --- src/pages/blog/[slug].astro | 20 +++++++++++++++++++- src/pages/configurations/[slug].astro | 26 +++++++++++++++++++++++--- src/pages/projects/[slug].astro | 26 +++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/pages/blog/[slug].astro b/src/pages/blog/[slug].astro index 3ade70d..74b48bb 100644 --- a/src/pages/blog/[slug].astro +++ b/src/pages/blog/[slug].astro @@ -48,6 +48,24 @@ const formatDate = (date) => { }); }; +// Generate datetime attribute safely +const getISODate = (date) => { + if (!date) return ''; + // Handle various date formats + try { + // If already a Date object + if (date instanceof Date) { + return date.toISOString(); + } + // If it's a string or number, convert to Date + return new Date(date).toISOString(); + } catch (error) { + // Fallback if date is invalid + console.error('Invalid date format:', date); + return ''; + } +}; + // Get the Content component for rendering markdown const { Content } = await post.render(); --- @@ -57,7 +75,7 @@ const { Content } = await post.render();

{post.data.title}