--- import { getCollection } from "astro:content"; import PrettyDate from "./PrettyDate.astro"; // import Tags from "./Tags.astro"; import type { CollectionEntry } from "astro:content"; interface Props { limit?: number; } const { limit = Infinity } = Astro.props; const posts = (await getCollection("blog")) .sort((a, b) => b.data.publish_date.valueOf() - a.data.publish_date.valueOf()) .slice(0, limit); type Post = CollectionEntry<"blog">; const postsByYear = Object.entries( posts.reduce( (acc, post) => { const year = post.data.publish_date.getFullYear().toString(); acc[year] ??= []; acc[year].push(post); return acc; }, {} as Record, ), ).sort(([year1], [year2]) => year2.localeCompare(year1)); ---
{ postsByYear.map(([year, posts]) => { if (!posts) return null; return ( <>

{year}

); }) }