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 &&
+ }