Fix BlogPost layout frontmatter and stabilize blog rendering
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user