--- import BaseLayout from '../layouts/base.astro'; import events from '../events.json'; import EventItem from '../components/EventItem.astro'; import { isFuture } from 'date-fns'; function eventsFilter (year, future=true) { return function (x) { if (!x.date.match(new RegExp(`^${year}`))) { return false } const isDate = x.date.match(/^\d{4}-\d{2}-\d{2}$/) if (!isDate) { return false } return future ? isFuture(new Date(x.date)) : !isFuture(new Date(x.date)) } } const currentYear = "2024"; const pastYears = [ 2023, 2024 ]; const upcoming = events.filter(x => x.date.match(/^2024/)) const past = {} for (const year of pastYears.reverse()) { past[year] = events.filter(eventsFilter(year, false)).reverse() } ---

Upcoming events in 2024

{upcoming.map((event) => ( ))}

Past events

{pastYears.map((year) => ( past[year].length > 0 &&

{year}

{past[year]?.map((event) => ( ))}
))}

Source repository