Show past events as past events

This commit is contained in:
tree🌴 2024-05-18 17:11:05 +02:00
parent dd8adc6924
commit bc637c3457
3 changed files with 24 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import core from '../core.json';
import EventItem from '../components/EventItem.astro';
import { isFuture } from 'date-fns';
import { types, countryNames } from '../lib/events.js';
import { isFutureDate } from '../lib/date';
const { type: selectedType } = Astro.props;
const { country: selectedCountry } = Astro.props;
@ -43,12 +44,22 @@ function eventsFilter (year, future=true) {
}
const pastYears = [...new Set(events.map(e => e.date.match(/^(\d{4})/)[1]))];
const upcoming = events.filter(x => x.date.match(/^2024/))
let upcomingEvents = [];
let pastEvents = [];
for (const e of events) {
if (isFutureDate(e.date)) {
upcomingEvents.push(e)
} else {
pastEvents.push(e)
}
}
const upcoming = events.filter(x => isFutureDate(x.date))
const past = {}
let pastTotal = 0
for (const year of pastYears.reverse()) {
past[year] = events.filter(eventsFilter(year, false)).reverse()
past[year] = pastEvents.filter(eventsFilter(year, false)).reverse()
pastTotal += past[year].length
}

8
src/lib/date.js Normal file
View file

@ -0,0 +1,8 @@
import { isPast } from 'date-fns';
export function isFutureDate (dt) {
if (dt.match(/^\d{4}-\d{2}-\d{2}$/) && isPast(new Date(dt))) {
return false
}
return true
}

View file

@ -7,8 +7,9 @@ import articles from '../articles.json';
import talks from '../talks.json';
import explorer from '../explorer.json';
import dbRepo from '../db-repo.json';
import { isPast, format } from 'date-fns';
import { format } from 'date-fns';
import EventItem from '../components/EventItem.astro';
import { isFutureDate } from '../lib/date';
const events = core.events;
@ -16,10 +17,7 @@ const upcomingEvents = []
let eventsPast = 0
let eventsUpcoming = 0
for (const ev of events) {
let future = true
if (ev.date.match(/^\d{4}-\d{2}-\d{2}$/) && isPast(new Date(ev.date))) {
future = false
}
let future = isFutureDate(ev.date)
if (future) {
upcomingEvents.push(ev)
eventsUpcoming++