SanYeCao-blog/src/components/Posts/PostList.astro

28 lines
613 B
Text
Raw Normal View History

2026-03-24 17:33:01 +00:00
---
2026-03-24 18:01:45 +00:00
import { getCollection } from "astro:content";
2026-03-24 17:33:01 +00:00
import PostItem from "./PostItem.astro";
2026-03-24 22:50:33 +00:00
import { getLangFromUrl, getTranslations, type Lang } from "@/i18n";
2026-03-24 17:33:01 +00:00
2026-03-24 22:50:33 +00:00
const lang = getLangFromUrl(Astro.url);
const t = getTranslations(lang);
2026-03-24 18:01:45 +00:00
const allPosts = await getCollection("blog");
2026-03-24 17:33:01 +00:00
---
<ul>
2026-03-24 18:01:45 +00:00
{
allPosts.map((post: any) => {
const formattedDate = new Date(post.data.pubDate)
.toISOString()
.split("T")[0];
2026-03-24 17:33:01 +00:00
2026-03-24 18:01:45 +00:00
return (
<PostItem
2026-03-24 22:50:33 +00:00
url={`/${lang}/posts/${post.id}/`}
2026-03-24 18:01:45 +00:00
title={post.data.title}
date={formattedDate}
/>
);
})
}
2026-03-24 17:33:01 +00:00
</ul>