2025-06-10 14:05:48 +00:00
|
|
|
---
|
2025-06-11 16:05:50 +00:00
|
|
|
import type { CollectionEntry } from "astro:content";
|
2025-06-10 14:05:48 +00:00
|
|
|
import { getCollection } from "astro:content";
|
|
|
|
import Layout from "../../layouts/BaseLayout.astro";
|
2025-06-10 14:17:48 +00:00
|
|
|
import PostElement from "../../components/PostElement.astro";
|
2025-06-10 14:05:48 +00:00
|
|
|
|
|
|
|
const posts = await getCollection("blog", ({ data }) => {
|
|
|
|
return data.draft !== true;
|
|
|
|
});
|
|
|
|
|
|
|
|
posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime());
|
2025-06-11 16:05:50 +00:00
|
|
|
|
|
|
|
const postsByYear = posts.reduce<Record<string, CollectionEntry<"blog">[]>>((acc, post) => {
|
|
|
|
const year = post.data.pubDate.getFullYear().toString();
|
|
|
|
if (!acc[year]) {
|
|
|
|
acc[year] = [];
|
|
|
|
}
|
|
|
|
acc[year].push(post);
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const years = Object.keys(postsByYear).sort((a, b) => Number(b) - Number(a));
|
2025-06-10 14:05:48 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
<Layout>
|
|
|
|
<section style={{ "margin-top": "3rem" }}>
|
2025-06-11 16:05:50 +00:00
|
|
|
{
|
|
|
|
years.map((year) => (
|
|
|
|
<div>
|
|
|
|
<div style={{ "margin-bottom": "1rem" }}>{year}</div>
|
|
|
|
<ul>
|
|
|
|
{postsByYear[year].map((post) => (
|
|
|
|
<PostElement post={post} />
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
}
|
2025-06-10 14:05:48 +00:00
|
|
|
</section>
|
|
|
|
</Layout>
|