Fix BlogPost layout frontmatter and stabilize blog rendering

This commit is contained in:
scadmin
2025-12-16 20:01:14 +00:00
parent 0782fe7c82
commit bcf5724d38
7 changed files with 141 additions and 205 deletions

View File

@@ -6,10 +6,10 @@ import { SITE_DESCRIPTION, SITE_TITLE } from '../consts';
import { getCollection } from 'astro:content';
const posts = (await getCollection('blog'))
.filter((p) => !(p.data as { draft?: boolean }).draft)
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.slice(0, 5);
const latest = (await getCollection('blog'))
.filter((p) => !(((p.data as any).draft) ?? false))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.slice(0, 5);
---
<!doctype html>
@@ -41,27 +41,20 @@ const posts = (await getCollection('blog'))
<hr />
<h2>Latest Posts</h2>
{posts.length === 0 ? (
<p>No posts yet. Check back soon.</p>
{latest.length === 0 ? (
<p>No posts yet.</p>
) : (
<>
<ul>
{posts.map((post) => (
<li>
<a href={`/blog/${post.id}`}>{post.data.title}</a>
<small> — {post.data.pubDate.toLocaleDateString()}</small>
{post.data.description ? <p>{post.data.description}</p> : null}
</li>
))}
</ul>
<p>
<a href="/blog">View all posts →</a>
</p>
</>
<ul>
{latest.map((post) => (
<li>
<a href={`/blog/${post.id}/`}>{post.data.title}</a>
{post.data.description ? <p>{post.data.description}</p> : null}
</li>
))}
</ul>
)}
</main>
<Footer />
</body>
</html>