import Head from "next/head" import Link from 'next/link' import { Post, SerializablePost, getPostSlugs, loadSinglePage } from "~/utils/post" import styles from "~/styles/index.module.css" interface PageProps { sortedPosts: SerializablePost[] } export async function getStaticProps(): Promise<{ props: PageProps }> { const slugs = await getPostSlugs() const posts = await Promise.all(slugs.map(loadSinglePage)) const sortedPosts = posts .sort((a: Post, b: Post) => b.date.valueOf() - a.date.valueOf()) .map((post: Post): SerializablePost => ({ ...post, date: post.date.toISOString() })) return { props: { sortedPosts } } } export default function Index({ sortedPosts }: PageProps) { const deserializedPosts = sortedPosts.map((post: SerializablePost): Post => ({ ...post, date: new Date(post.date) })) return ( <> All posts

All posts

{deserializedPosts.map((post: Post, i: number) => ( <> {i >= 1 && deserializedPosts[i - 1].date.getFullYear() != post.date.getFullYear() && (

{post.date.getFullYear()}

)}

{post.title}

{post.date.toLocaleDateString()}

{post.subtitle}

))} ); }