import Content from "../../components/Content"; import Link from "../../components/Link"; import Time from "../../components/Time"; import { getAllPosts } from "../../lib/helpers/posts"; import config from "../../lib/config/constants"; import { metadata as defaultMetadata } from "../layout"; import type { ReactElement } from "react"; import type { Metadata, Route } from "next"; import type { FrontMatter } from "../../lib/helpers/posts"; import styles from "./page.module.css"; export const metadata: Metadata = { title: "Notes", description: `Recent posts by ${config.authorName}.`, openGraph: { ...defaultMetadata.openGraph, title: "Notes", url: "/notes", }, alternates: { ...defaultMetadata.alternates, canonical: "/notes", }, }; export default async function Page() { // parse the year of each note and group them together const notes = await getAllPosts(); const notesByYear: { [year: string]: FrontMatter[]; } = {}; notes.forEach((note) => { const year = new Date(note.date).getUTCFullYear(); (notesByYear[year] || (notesByYear[year] = [])).push(note); }); const sections: ReactElement[] = []; Object.entries(notesByYear).forEach(([year, posts]) => { sections.push(

{year}

); }); // grouped posts enter this component ordered chronologically -- we want reverse chronological const reversed = sections.reverse(); return {reversed}; }