|
| 1 | +import type { APIRoute } from 'astro'; |
| 2 | +import { loadNodes, canonicalEventId } from '../lib/nodes'; |
| 3 | + |
| 4 | +export const GET: APIRoute = async ({ site }) => { |
| 5 | + const nodes = await loadNodes(); |
| 6 | + const siteUrl = site!.href.replace(/\/$/, ''); |
| 7 | + const base = import.meta.env.BASE_URL.replace(/\/$/, ''); |
| 8 | + |
| 9 | + const events = nodes |
| 10 | + .filter((node) => !node.placeholder) |
| 11 | + .map((node) => ({ |
| 12 | + id: node.id, |
| 13 | + uid: node.uid, |
| 14 | + canonical_url: `${siteUrl}${base}/event/${canonicalEventId(node)}/`, |
| 15 | + event_name: node.event_name, |
| 16 | + city: node.city ?? null, |
| 17 | + country: node.country ?? null, |
| 18 | + location_name: node.location_name ?? null, |
| 19 | + address: node.address ?? null, |
| 20 | + location_tbd: node.location_tbd ?? false, |
| 21 | + plus_code: node.plus_code, |
| 22 | + lat: node.lat, |
| 23 | + lng: node.lng, |
| 24 | + event_date: node.event_date ?? null, |
| 25 | + event_end_date: node.event_end_date ?? null, |
| 26 | + event_start_time: node.event_start_time ?? null, |
| 27 | + event_end_time: node.event_end_time ?? null, |
| 28 | + date_tbd: node.date_tbd ?? false, |
| 29 | + time_tbd: node.time_tbd ?? false, |
| 30 | + online_event: node.online_event ?? false, |
| 31 | + event_url: node.event_url ?? null, |
| 32 | + event_page_url: node.event_page_url ?? null, |
| 33 | + event_short_description: node.event_short_description, |
| 34 | + details_text: node.details_text, |
| 35 | + event_activities: node.event_activities, |
| 36 | + organizers: node.organizers, |
| 37 | + organization_name: node.organization_name ?? null, |
| 38 | + organization_url: node.organization_url ?? null, |
| 39 | + organization_type: node.organization_type ?? null, |
| 40 | + forum_thread_url: node.forum_thread_url ?? null, |
| 41 | + })); |
| 42 | + |
| 43 | + const payload = { |
| 44 | + schema_version: 1, |
| 45 | + generated_at: new Date().toISOString(), |
| 46 | + event_count: events.length, |
| 47 | + events, |
| 48 | + }; |
| 49 | + |
| 50 | + return new Response(JSON.stringify(payload, null, 2), { |
| 51 | + headers: { 'Content-Type': 'application/json' }, |
| 52 | + }); |
| 53 | +}; |
0 commit comments