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

27 lines
613 B
Text

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