diff --git a/docker-compose.yml b/docker-compose.yml index 5bf3759..8115400 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,6 +70,8 @@ services: environment: PUBLIC_SITE_URL: ${PUBLIC_SITE_URL} DIRECTUS_URL: ${DIRECTUS_URL} + DIRECTUS_PUBLIC_URL: ${DIRECTUS_PUBLIC_URL} + DIRECTUS_PORT: ${DIRECTUS_PORT} DIRECTUS_ADMIN_TOKEN: ${DIRECTUS_ADMIN_TOKEN} depends_on: directus: diff --git a/src/components/EventsList.astro b/src/components/EventsList.astro index 9261914..c19fd9b 100644 --- a/src/components/EventsList.astro +++ b/src/components/EventsList.astro @@ -16,24 +16,29 @@ const { events, title = 'Upcoming events', description = 'A quick scan list for
{events.length > 0 ? ( - events.map((event) => ( -
-
-
-

{event.is_featured ? 'Featured' : 'Event'}

-

{event.title}

-

{event.description}

+ events.map((event) => { + const detailHref = event.slug ? `/events/${event.slug}/` : undefined; + + return ( +
+
+
+

{event.is_featured ? 'Featured' : 'Event'}

+

{detailHref ? {event.title} : event.title}

+

{event.description}

+
+
+

{formatDateTime(event.start_datetime)}

+ {event.location_text &&

{event.location_text}

} + {detailHref &&

View event

} + {event.registration_link && ( +

Register

+ )} +
-
-

{formatDateTime(event.start_datetime)}

- {event.location_text &&

{event.location_text}

} - {event.registration_link && ( -

Register

- )} -
-
-
- )) + + ); + }) ) : (

No events published

diff --git a/src/lib/fallback-data.ts b/src/lib/fallback-data.ts index 1cc4692..a751dd9 100644 --- a/src/lib/fallback-data.ts +++ b/src/lib/fallback-data.ts @@ -24,6 +24,7 @@ export type EventItem = { end_datetime?: string; location_text?: string; registration_link?: string; + realimage?: string | { id?: string; filename_download?: string; title?: string }; status?: string; is_featured?: boolean; tags?: string[]; diff --git a/src/pages/events/[slug].astro b/src/pages/events/[slug].astro index d71802d..9a8990f 100644 --- a/src/pages/events/[slug].astro +++ b/src/pages/events/[slug].astro @@ -5,18 +5,46 @@ import { formatDateTime } from '../../lib/format'; type EventItem = Awaited>[number]; +declare const process: { + env: Record; +}; + +function resolveEventImageSource(realimage: EventItem['realimage']): string | null { + if (!realimage) return null; + + const candidate = typeof realimage === 'string' ? realimage : realimage.id; + if (!candidate) return null; + + if (candidate.startsWith('http://') || candidate.startsWith('https://') || candidate.startsWith('/')) { + return candidate; + } + + const configuredPublicUrl = process.env.DIRECTUS_PUBLIC_URL; + const directusPort = process.env.DIRECTUS_PORT ?? '8066'; + const localFallbackUrl = `${Astro.url.protocol}//${Astro.url.hostname}:${directusPort}`; + const directusBaseUrl = + configuredPublicUrl && !configuredPublicUrl.includes('example.com') + ? configuredPublicUrl + : localFallbackUrl; + + return new URL(`/assets/${candidate}`, directusBaseUrl).toString(); +} + export async function getStaticPaths() { const events = await getEvents(); return events.map((item) => ({ params: { slug: item.slug }, props: { item } })); } const { item } = Astro.props as { item: EventItem }; +const imageSrc = resolveEventImageSource(item.realimage); +const imageAlt = item.title; ---

{formatDateTime(item.start_datetime)}

{item.title}

+ {imageSrc &&

{imageAlt}

}

{item.description}

{item.location_text &&

Location: {item.location_text}

} {item.registration_link &&

Register

}