web/src/pages/events.astro

79 lines
1.9 KiB
Text
Raw Normal View History

2023-11-13 03:03:34 +01:00
---
import BaseLayout from '../layouts/base.astro';
2023-11-24 10:56:28 +01:00
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()
}
2023-11-13 03:03:34 +01:00
---
<BaseLayout title="Events">
<div>
</div>
<div class="middle-pane-medium mt-10">
2023-11-24 10:56:28 +01:00
<!--div class="mb-10">
<img src="/events-map.svg" class="w-full" />
</div-->
2023-12-20 23:14:44 +01:00
<h1 id="upcoming">Upcoming ({upcoming.length})</h1>
2023-11-24 10:56:28 +01:00
<div class="mb-10">
{upcoming.map((event) => (
<EventItem item={event} />
))}
</div>
2023-12-20 23:14:44 +01:00
<h1 id="past">Past events ({events.length-upcoming.length})</h1>
2023-11-24 10:56:28 +01:00
{pastYears.map((year) => (
past[year].length > 0 &&
2023-12-20 23:14:44 +01:00
<h2>{year} ({past[year].length})</h2>
2023-11-24 10:56:28 +01:00
<div class="mt-4 mb-10">
{past[year]?.map((event) => (
<EventItem item={event} />
))}
</div>
))}
2023-11-24 13:16:13 +01:00
<p>
<a href="https://github.com/web3privacy/events" class="hover:underline">Source repository</a>
</p>
2023-11-13 03:03:34 +01:00
</div>
2023-11-24 10:56:28 +01:00
<script>
2023-11-24 12:39:36 +01:00
document.querySelectorAll('.event-header .header-base').forEach((el) => {
el.addEventListener('click', (ev) => {
if (ev.target.tagName === "BUTTON") {
return false;
}
const detail = el.parentElement.parentElement.querySelector('.detail')
2023-11-24 10:56:28 +01:00
document.querySelectorAll('.detail:not(.hidden)').forEach(e => (detail !== e ? e.classList.add('hidden') : null));
detail.classList.toggle('hidden');
});
});
</script>
2023-11-13 03:03:34 +01:00
</BaseLayout>