From a718a3ae801c0c2f66e55e3851295a8c8b6691a5 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Tue, 12 Nov 2024 20:45:48 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20pages=20=C3=A9v=C3=A8nements=20vides?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/contentful.ts | 11 +++++++++++ src/pages/evenements/[slug].astro | 27 ++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/lib/contentful.ts b/src/lib/contentful.ts index 93c92de..70f5774 100644 --- a/src/lib/contentful.ts +++ b/src/lib/contentful.ts @@ -77,3 +77,14 @@ export const fetchEvenements = async () => { .map(evenementFromContentfull) .filter(estÀVenir) } + +export const fetchEvenement = async (slug: string) => { + const entries = await contentfulClient.getEntries({ + content_type: "evenement", + "fields.slug": slug + }); + + if (!entries.items.length) return + + return evenementFromContentfull(entries.items[0]!) +} diff --git a/src/pages/evenements/[slug].astro b/src/pages/evenements/[slug].astro index 0e8921f..55a3dda 100644 --- a/src/pages/evenements/[slug].astro +++ b/src/pages/evenements/[slug].astro @@ -1,40 +1,29 @@ --- import type { Document } from '@contentful/rich-text-types'; import { documentToHtmlString } from "@contentful/rich-text-html-renderer"; -import { fetchEvenements} from "../../lib/contentful"; +import {fetchEvenement, fetchEvenements} from "../../lib/contentful"; import Layout from "../../layouts/Layout.astro"; import Card from "../../components/Card.astro"; export const prerender = false -export async function getStaticPaths() { - const evenement = await fetchEvenements() - return evenement.map((evenement) => ({ - params: {slug: evenement.slug}, - props: { - nom: evenement.nom, - description: evenement.description ? documentToHtmlString(evenement.description as Document) : "", - date: evenement.date ? new Date(evenement.date as string).toLocaleDateString() : "", - lieu: evenement.lieu, - lieuUrl: evenement.lieuUrl, - affiche: evenement.affiche - }, - })); -} +const {slug} = Astro.params + +const { nom, description, date, lieu, lieuUrl, affiche } = await fetchEvenement(slug) -const { nom, description, date, lieu, lieuUrl, affiche } = Astro.props; const Wrapper = lieuUrl ? 'a' : 'div' ---

{nom}

{affiche && `Affiche} - +
à {lieu}
- -
+ { + description &&
+ }