blob: 04ce9fe46f44d9bdb6695455917f6f4ce390ba51 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
---
import { getCollection } from "astro:content";
import dayjs from "dayjs";
const posts = await getCollection("blog", ({ data }) => {
return data.draft !== true;
});
posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
const latestPosts = posts.slice(0, 5);
---
<style lang="scss">
@use "../../scss/variables" as *;
small {
font-size: $fontSizeBase * 0.75;
opacity: 0.5;
}
</style>
<section>
<h2>Latest posts</h2>
<ul>
{
latestPosts.map((post) => (
<li>
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
<small>{dayjs(post.data.pubDate.toString()).format("MMMM DD, YYYY")}</small>
</li>
))
}
</ul>
</section>
|