main
 1---
 2import { getCollection } from "astro:content";
 3import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
 4import { getIntlayer } from "intlayer";
 5import PostsList from "@/components/widgets/PostsList.astro";
 6import { SITE_CONFIG } from "@/config.ts";
 7import BaseLayout from "@/layouts/BaseLayout.astro";
 8import { getLocalePosts } from "@/utils/content.ts";
 9import { getLocaleRouteParam } from "@/utils/url.ts";
10
11type Props = InferGetStaticPropsType<typeof getStaticPaths>;
12
13export const getStaticPaths = (() => {
14  return SITE_CONFIG.locales.map((locale) => ({
15    params: { locale: getLocaleRouteParam(locale) },
16  }));
17}) satisfies GetStaticPaths;
18
19const locale = Astro.currentLocale;
20const globalI18n = getIntlayer("global", locale);
21
22const posts = getLocalePosts(await getCollection("posts"), locale);
23const sortedPosts = posts.sort((a, b) =>
24  Temporal.ZonedDateTime.compare(b.data.date, a.data.date),
25);
26const postsByYear = sortedPosts.reduce(
27  (acc, post) => {
28    const year = Temporal.ZonedDateTime.from(post.data.date).year;
29    if (!acc[year]) {
30      acc[year] = [];
31    }
32    acc[year].push(post);
33    return acc;
34  },
35  {} as Record<number, typeof posts>,
36);
37---
38
39<BaseLayout title={globalI18n.posts.title}>
40  <div style={{ fontSize: "1.2rem" }}>
41    <h1>{globalI18n.posts.title}</h1>
42    {Object.entries(postsByYear)
43      .reverse()
44      .map(([year, posts]) => (
45        <section>
46          <h2>{year}</h2>
47          <PostsList posts={posts} />
48        </section>
49      ))}
50  </div>
51</BaseLayout>