diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 0b786fd..d0742aa 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -4,24 +4,40 @@ 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() + (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}
+ +
+ ))}