--- import { getCollection, type CollectionEntry } from "astro:content"; import BaseLayout from "../layouts/BaseLayout.astro"; import ReadingEntry from "../components/ReadingEntry.astro"; import "../styles/post.css"; import "../styles/sitemap.css"; type ReadingYear = CollectionEntry<"reading">; type Entry = ReadingYear["data"]["entries"][number]; const years = await getCollection("reading"); years.sort((a: ReadingYear, b: ReadingYear) => b.data.year - a.data.year); // Entries are authored oldest-first within a year; show the most recent first. function newestFirst(entries: Entry[]): Entry[] { return [...entries].reverse(); } ---
{ years.map((year: ReadingYear) => { const entries = newestFirst(year.data.entries); const books = entries.filter((e: Entry) => e.type === "book"); const articles = entries.filter( (e: Entry) => e.type === "article", ); return (

{year.data.year}

    {books.map((entry: Entry) => ( ))}
{articles.length > 0 && (

Articles

    {articles.map((entry: Entry) => ( ))}
)}
); }) }