Fixes error due to missing date
This commit is contained in:
@@ -20,7 +20,7 @@ const { title, description, pubDate, updatedDate, heroImage } = Astro.props;
|
|||||||
<div class="prose">
|
<div class="prose">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<div class="date">
|
<div class="date">
|
||||||
<FormattedDate date={pubDate} />
|
{ pubDate && <FormattedDate date={pubDate} /> }
|
||||||
{
|
{
|
||||||
updatedDate && (
|
updatedDate && (
|
||||||
<div class="last-updated-on">
|
<div class="last-updated-on">
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
---
|
---
|
||||||
import NotchedBox from '../../components/NotchedBox.astro';
|
import NotchedBox from '../../components/NotchedBox.astro';
|
||||||
import RootLayout from '../../layouts/RootLayout.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 FormattedDate from '../../components/FormattedDate.astro';
|
||||||
import { Image } from 'astro:assets';
|
import { Image } from 'astro:assets';
|
||||||
|
|
||||||
const posts = (await getCollection('blog'))
|
function publishedOnly(p: CollectionEntry<'blog'>): p is (CollectionEntry<'blog'> & { data: { pubDate: Date }}) {
|
||||||
.filter(p => p.data.pubDate)
|
return p.data.pubDate !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const posts = (await getCollection('blog', publishedOnly))
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
|
(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 &&
|
||||||
<p class="description">
|
<p class="description">
|
||||||
{post.data.description}
|
{post.data.description}
|
||||||
</p>}
|
</p>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</NotchedBox>
|
</NotchedBox>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user