--- 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 ({upcoming.length})

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

Past events ({events.length-upcoming.length})

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

{year} ({past[year].length})

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

Source repository