Migrate Site to German as Default Locale

This commit is contained in:
2024-03-09 13:53:43 +01:00
parent fd56de0451
commit 9312089e96
26 changed files with 109 additions and 486 deletions

View File

@@ -0,0 +1,35 @@
---
import {getCollection} from "astro:content";
import PageLayout from "../../layouts/PageLayout.astro";
import {astroI18n, t} from "astro-i18n";
import PostComponent from "../../components/PostComponent.astro";
import dayjs from "dayjs";
async function getPosts() {
const posts = await getCollection("announcements", entry => entry.id.split("/")[0] === astroI18n.locale);
const germanPosts = await getCollection("announcements", entry => entry.id.split("/")[0] === "de");
germanPosts.forEach(value => {
if (posts.find(post => post.data.key === value.data.key)) {
return;
} else {
posts.push(value);
}
});
return posts.sort((a, b) => dayjs(b.data.created).unix() - dayjs(a.data.created).unix()).filter((value, index) => index < 20);
}
const posts = await getPosts();
---
<PageLayout title={t("blog.title")}>
{posts.map((post, index) => (
<div>
<PostComponent post={post}/>
{index !== posts.length - 1 &&
<hr/>}
</div>
))}
</PageLayout>