From 75c9322fd004a29a607bbaf8afc6601fbd3e560e Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Thu, 31 Jul 2025 14:59:14 -0700 Subject: [PATCH] Fixes error due to missing date --- src/layouts/BlogPost.astro | 2 +- src/pages/blog/index.astro | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro index 2c04f0c..c708b29 100644 --- a/src/layouts/BlogPost.astro +++ b/src/layouts/BlogPost.astro @@ -20,7 +20,7 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
- + { pubDate && } { updatedDate && (
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index b047a72..3a9f459 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,12 +1,15 @@ --- import NotchedBox from '../../components/NotchedBox.astro'; import RootLayout from '../../layouts/RootLayout.astro'; -import { getCollection } from 'astro:content'; +import { getCollection, type CollectionEntry } from 'astro:content'; import FormattedDate from '../../components/FormattedDate.astro'; import { Image } from 'astro:assets'; -const posts = (await getCollection('blog')) - .filter(p => p.data.pubDate) +function publishedOnly(p: CollectionEntry<'blog'>): p is (CollectionEntry<'blog'> & { data: { pubDate: Date }}) { + return p.data.pubDate !== undefined; +} + +const posts = (await getCollection('blog', publishedOnly)) .sort( (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(), ); @@ -57,7 +60,8 @@ const posts = (await getCollection('blog')) { post.data.description &&

{post.data.description} -

} +

+ }