--- import { getCollection } from 'astro:content'; import FormattedDate from '../../components/FormattedDate.astro'; import SectionContainer from '../../components/SectionContainer.astro'; const posts = (await getCollection('blog')).sort( (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf() ); // Group posts by year const postsByYear = posts.reduce((acc, post) => { const year = new Date(post.data.pubDate).getFullYear(); if (!acc[year]) { acc[year] = []; } acc[year].push(post); return acc; }, {}); // Sort the years const sortedYears = Object.keys(postsByYear).sort((a, b) => b - a); ---

Blog posts

{sortedYears.map(year => (
{year}
))}