2024-02-24 02:12:40 +01:00
|
|
|
import { format, compareAsc, addDays, isFuture } from 'date-fns';
|
|
|
|
|
2024-03-02 17:00:23 +01:00
|
|
|
export const types = [
|
|
|
|
{ id: "", plural: 'All events'},
|
|
|
|
{ id: "meetup", name: 'Meetup', plural: 'Meetups' },
|
|
|
|
{ id: "summit", name: 'Summit', plural: 'Summits' },
|
|
|
|
{ id: "privacy-corner", name: 'Privacy Corner', plural: 'Privacy Corners' },
|
|
|
|
{ id: "online-summit", name: 'Online Summit', plural: 'Online Summits' },
|
2024-03-16 03:59:14 +01:00
|
|
|
{ id: 'meta-hackathon', name: 'Meta-hackathon', plural: 'Meta-hacktahons'},
|
2024-03-02 17:00:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
export const countryNames = {
|
|
|
|
cz: 'Czechia',
|
|
|
|
it: 'Italy',
|
|
|
|
de: 'Germany',
|
|
|
|
es: 'Spain',
|
|
|
|
si: 'Slovenia',
|
|
|
|
dk: 'Denmark',
|
|
|
|
pl: 'Poland',
|
|
|
|
be: 'Belgium',
|
|
|
|
pt: 'Portugal',
|
|
|
|
ee: 'Estonia',
|
|
|
|
nl: 'Netherlands',
|
|
|
|
ro: 'Romania',
|
|
|
|
gr: 'Greece',
|
|
|
|
th: 'Thailand',
|
|
|
|
}
|
|
|
|
|
2024-02-24 02:12:40 +01:00
|
|
|
export function dateInfo (item) {
|
|
|
|
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
|
|
|
|
|
|
|
|
return { isDate, isFuture: future, year }
|
|
|
|
}
|
|
|
|
|
2024-03-16 23:31:19 +01:00
|
|
|
export function dateFormat (str, fmt) {
|
2024-02-24 02:12:40 +01:00
|
|
|
if (str.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
2024-03-16 23:31:19 +01:00
|
|
|
return format(new Date(str), fmt || 'MMM d, yyyy')
|
2024-02-24 02:12:40 +01:00
|
|
|
}
|
|
|
|
const qm = str.match(/^(\d{4})\/(\w+)$/)
|
|
|
|
if (qm) {
|
|
|
|
return `${qm[2]}, ${qm[1]}`
|
|
|
|
}
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
|
|
|
export function dateEnd(str, days) {
|
|
|
|
return format(addDays(new Date(str), days-1), 'yyyy-MM-dd');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function nameRenderer (item, full = false) {
|
|
|
|
let num;
|
|
|
|
let ccm = item.coincidence?.match(/\[(\w+)\]/)
|
|
|
|
let cc = ccm && ccm[1] ? ccm[1] : (item.coincidence ? item.coincidence : null)
|
|
|
|
const date = dateInfo(item)
|
|
|
|
switch (item.type) {
|
|
|
|
case 'summit':
|
2024-02-24 03:18:30 +01:00
|
|
|
//num = item.id.match(/^w3ps(\d+)$/)[1]
|
2024-02-24 02:12:40 +01:00
|
|
|
return `Summmit ${item.city}` + (full ? ` ${date.year}`: '')// + (cc ? ` @ ${cc}` : '')
|
|
|
|
break;
|
|
|
|
case 'meetup':
|
2024-02-24 03:18:30 +01:00
|
|
|
//num = item.id.match(/(\d+)$/)
|
2024-02-24 02:12:40 +01:00
|
|
|
return `Meetup ${item.city}` + (full ? ` ${date.year}`: '')// + (cc ? ` @ ${cc}` : '')
|
|
|
|
break;
|
|
|
|
case 'hackathon':
|
2024-02-24 03:18:30 +01:00
|
|
|
//num = item.id.match(/^w3ph(\d+)$/)[1]
|
2024-02-24 02:12:40 +01:00
|
|
|
return `Hackathon ${item.city}` + (full ? ` ${date.year}`: '')// + (cc ? ` @ ${cc}` : '')
|
|
|
|
break;
|
|
|
|
case 'privacy-corner':
|
|
|
|
return `Privacy Corner at `+ (item.coincidenceFull ? item.coincidenceFull : `${item.coincidence} ${date.year}`)
|
|
|
|
break;
|
2024-03-02 17:00:23 +01:00
|
|
|
case 'online-summit':
|
|
|
|
return "ONLINE Summit" + (item['name-extension'] ? ' ' + item['name-extension'] : '') + (full ? ` ${date.year}` : '');
|
|
|
|
break;
|
2024-03-16 03:59:14 +01:00
|
|
|
case 'meta-hackathon':
|
|
|
|
return `Meta-hackathon ${item.city}` + (full ? ` ${date.year}`: '')
|
|
|
|
break;
|
2024-02-24 02:12:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ccRenderer (item) {
|
|
|
|
let ccm = item.coincidence?.match(/\[(\w+)\]/)
|
|
|
|
let cc = ccm && ccm[1] ? ccm[1] : (item.coincidence ? item.coincidence : null)
|
|
|
|
return cc
|
|
|
|
}
|
|
|
|
|
|
|
|
export function eventStatus (item) {
|
|
|
|
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 date = dateInfo(item)
|
|
|
|
return item.confirmed
|
|
|
|
? (date.isDate ? statuses.past : statuses.confirmed)
|
|
|
|
: (item.links?.rsvp ? statuses.preregistration : statuses.unconfirmed);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSpeaker (core, id) {
|
|
|
|
return core.people.find(p => p.id === id)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findExt (eventsExt, item) {
|
|
|
|
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)
|
2024-03-07 15:55:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getEventPoster (item) {
|
2024-03-07 18:14:39 +01:00
|
|
|
if (item.thumbs && item.thumbs['poster-simple:640']) {
|
|
|
|
return item.thumbs['poster-simple:640']
|
|
|
|
}
|
|
|
|
if (item.thumbs && item.thumbs['poster:640']) {
|
|
|
|
return item.thumbs['poster:640']
|
|
|
|
}
|
|
|
|
|
2024-03-07 15:55:39 +01:00
|
|
|
if (item.images && item.images['poster-simple']) {
|
|
|
|
return item.images['poster-simple'];
|
|
|
|
}
|
|
|
|
if (item.images && item.images.poster) {
|
|
|
|
return item.images.poster;
|
|
|
|
}
|
|
|
|
return null
|
2024-03-07 18:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getSpeakerImage(speaker, size='400') {
|
|
|
|
if (speaker.thumbs && speaker.thumbs[size]) {
|
|
|
|
return speaker.thumbs[size];
|
|
|
|
}
|
|
|
|
return speaker.imageUrl;
|
2024-02-24 02:12:40 +01:00
|
|
|
}
|