diff --git a/src/components/EventItem.astro b/src/components/EventItem.astro index 732cb65..1b35f0e 100644 --- a/src/components/EventItem.astro +++ b/src/components/EventItem.astro @@ -1,104 +1,13 @@ --- const { item } = Astro.props; -import { format, compareAsc, addDays, isFuture } from 'date-fns'; import { marked } from 'marked'; import EventsExt from '../events-ext.json'; import core from "../core.json"; -import { imageMetadata } from 'astro/assets/utils'; - -function findExt () { - let slug = null - if (item.links?.web && item.links.web.match(/^https:\/\/lu.ma\//)) { - slug = item.links.web.match(/^https:\/\/lu.ma\/(.+)$/)[1] - } - if (item.links?.rsvp && item.links.rsvp.match(/^https:\/\/lu.ma\//)) { - slug = item.links.rsvp.match(/^https:\/\/lu.ma\/(.+)$/)[1] - } - if (!slug) { - return null - } - return EventsExt.find(ex => ex.url === slug) -} - -function getSpeaker (id) { - return core.people.find(p => p.id === id) -} - -const ext = findExt() - - -const isDate = item.date.match(/^\d{4}-\d{2}-\d{2}$/) -const future = isDate && !isFuture(new Date(item.date)); -const dateMatch = item.date.match(/^(\d{4})/) -const year = dateMatch ? dateMatch[1] : null - -function dateFormat (str) { - if (str.match(/^\d{4}-\d{2}-\d{2}$/)) { - return format(new Date(str), 'MMM d, yyyy') - } - const qm = str.match(/^(\d{4})\/(\w+)$/) - if (qm) { - return `${qm[2]}, ${qm[1]}` - } - return str -} - -function nameRenderer (item) { - let num; - let ccm = item.coincidence?.match(/\[(\w+)\]/) - let cc = ccm && ccm[1] ? ccm[1] : (item.coincidence ? item.coincidence : null) - switch (item.type) { - case 'summit': - num = item.id.match(/^w3ps(\d+)$/)[1] - return `W3PN Summmit #${num} ${item.city}`// + (cc ? ` @ ${cc}` : '') - break; - case 'meetup': - num = item.id.match(/(\d+)$/) - return `W3PN Meetup ${item.city} #${num ? num[1] : 'TBD'}`// + (cc ? ` @ ${cc}` : '') - break; - case 'hackathon': - num = item.id.match(/^w3ph(\d+)$/)[1] - return `W3PN Hackathon #${num} ${item.city}`// + (cc ? ` @ ${cc}` : '') - break; - case 'privacy-corner': - return `Privacy Corner at `+ (item.coincidenceFull ? item.coincidenceFull : `${item.coincidence} ${year}`) - break; - } -} - -function ccRenderer (item) { - let ccm = item.coincidence?.match(/\[(\w+)\]/) - let cc = ccm && ccm[1] ? ccm[1] : (item.coincidence ? item.coincidence : null) - return cc -} - -function dateEnd(str, days) { - return format(addDays(new Date(str), days-1), 'yyyy-MM-dd'); -} - -const statuses = { - preregistration: { - title: 'Pre-registration', - color: 'text-orange-500', - }, - unconfirmed: { - title: 'Planned', - color: '' - }, - confirmed: { - title: 'Confirmed', - color: 'text-green-500', - }, - past: { - title: 'Already happened', - color: 'text-green-800', - } -} - -const status = item.confirmed - ? (future ? statuses.past : statuses.confirmed) - : (item.links?.rsvp ? statuses.preregistration : statuses.unconfirmed); +import { dateFormat, dateInfo, dateEnd, nameRenderer, ccRenderer, eventStatus, getSpeaker, findExt } from '../lib/events.js'; +import SpeakerList from './SpeakerList.astro'; +const ext = findExt(EventsExt, item) +const status = eventStatus(item) ---