--- import Layout from '../../layouts/Layout.astro'; import { Icon } from 'astro-icon/components'; import { getLiveStory, storyblokEditable } from '@storyblok/astro'; import { fetchSpectacles, fetchAgenda, mapStoryToSpectacle } from '../../lib/storyblok'; // Requis pour le build statique (ignoré en SSR) export async function getStaticPaths() { const [spectacles, agenda] = await Promise.all([fetchSpectacles(), fetchAgenda()]); return spectacles.map(s => ({ params: { id: s.id }, props: { spectacle: s, upcomingDates: agenda .filter(event => event.spectacleId === s.id) .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()), }, })); } const { id } = Astro.params; const liveStory = await getLiveStory(Astro); let spectacle; let upcomingDates; if (liveStory) { spectacle = mapStoryToSpectacle(liveStory); const agenda = await fetchAgenda(); upcomingDates = agenda .filter(event => event.spectacleId === spectacle.id) .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()); } else if (Astro.props.spectacle) { ({ spectacle, upcomingDates } = Astro.props); } else { const [spectacles, agenda] = await Promise.all([fetchSpectacles(), fetchAgenda()]); spectacle = spectacles.find(s => s.id === id); upcomingDates = agenda .filter(event => event.spectacleId === id) .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()); } if (!spectacle) { return Astro.redirect('/spectacles/'); } ---
Tous les spectacles
{spectacle.title}
{spectacle.retired && (
Spectacle retraité
)}

{spectacle.title}

{spectacle.age}
{spectacle.duration && (
{spectacle.duration}
)}
{spectacle.summary && (
)} {spectacle.credits && (

{spectacle.credits}

)} {spectacle.dossierPro && spectacle.dossierPro !== '#' && ( Dossier Pédagogique )}
{spectacle.gallery.length > 0 && (

Galerie

{spectacle.gallery.map((img, index) => (
{`${spectacle.title}
))}
)} {upcomingDates.length > 0 && (

Prochaines dates

{upcomingDates.map(event => { const dateObj = new Date(event.date); return (
{dateObj.toLocaleString('fr-FR', { month: 'short' })} {dateObj.getDate()}
{dateObj.toLocaleString('fr-FR', { weekday: 'long', hour: '2-digit', minute: '2-digit' })}
{event.location}
{event.bookingLink && ( Réserver )}
); })}
)}