From e849d5980cd5e73cddbb31fe7239030059326fc5 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Thu, 12 Mar 2026 15:23:49 +0100 Subject: [PATCH] Ajouter le teaser YouTube sur la page spectacle --- src/lib/storyblok.ts | 9 +++++++++ src/pages/spectacles/[id].astro | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/lib/storyblok.ts b/src/lib/storyblok.ts index c6ada77..064549f 100644 --- a/src/lib/storyblok.ts +++ b/src/lib/storyblok.ts @@ -1,6 +1,13 @@ import { useStoryblokApi } from '@storyblok/astro'; import type { SbBlokData } from '@storyblok/astro'; +export function extractYouTubeId(url: string): string | null { + const match = url.match( + /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|shorts\/))([a-zA-Z0-9_-]{11})/ + ); + return match?.[1] ?? null; +} + function getVersion(): 'draft' | 'published' { return import.meta.env.PUBLIC_STORYBLOK_IS_PREVIEW === 'true' ? 'draft' : 'published'; } @@ -16,6 +23,7 @@ export interface Spectacle { credits: string; affiche: string; gallery: string[]; + teaser: string; dossierPro: string; dateCreation: string; _blok: SbBlokData; @@ -54,6 +62,7 @@ export function mapStoryToSpectacle(story: any): Spectacle { credits: c.credits || '', affiche: c.affiche?.filename || '', gallery: (c.galerie || []).map((a: any) => a.filename), + teaser: c.teaser || '', dossierPro: c.dossier?.filename || '', dateCreation: c.date_creation || '', _blok: c, diff --git a/src/pages/spectacles/[id].astro b/src/pages/spectacles/[id].astro index d3cd0a0..00aa3f3 100644 --- a/src/pages/spectacles/[id].astro +++ b/src/pages/spectacles/[id].astro @@ -2,7 +2,7 @@ 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'; +import { fetchSpectacles, fetchAgenda, mapStoryToSpectacle, extractYouTubeId } from '../../lib/storyblok'; // Requis pour le build statique (ignoré en SSR) export async function getStaticPaths() { @@ -46,6 +46,8 @@ if (!spectacle) { const now = new Date(); upcomingDates = upcomingDates.filter(event => new Date(event.date) >= now); + +const youtubeId = spectacle.teaser ? extractYouTubeId(spectacle.teaser) : null; --- @@ -121,6 +123,23 @@ upcomingDates = upcomingDates.filter(event => new Date(event.date) >= now); + + {youtubeId && ( +
+
+
+ +
+
+
+ )} + {upcomingDates.length > 0 && (