fix: pages évènements vides

main
Jalil Arfaoui 2024-11-12 20:45:48 +01:00
parent 502131f3ab
commit a718a3ae80
2 changed files with 19 additions and 19 deletions

View File

@ -77,3 +77,14 @@ export const fetchEvenements = async () => {
.map(evenementFromContentfull) .map(evenementFromContentfull)
.filter(estÀVenir) .filter(estÀVenir)
} }
export const fetchEvenement = async (slug: string) => {
const entries = await contentfulClient.getEntries<ContentFulEvenement>({
content_type: "evenement",
"fields.slug": slug
});
if (!entries.items.length) return
return evenementFromContentfull(entries.items[0]!)
}

View File

@ -1,40 +1,29 @@
--- ---
import type { Document } from '@contentful/rich-text-types'; import type { Document } from '@contentful/rich-text-types';
import { documentToHtmlString } from "@contentful/rich-text-html-renderer"; 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 Layout from "../../layouts/Layout.astro";
import Card from "../../components/Card.astro"; import Card from "../../components/Card.astro";
export const prerender = false export const prerender = false
export async function getStaticPaths() { const {slug} = Astro.params
const evenement = await fetchEvenements()
return evenement.map((evenement) => ({ const { nom, description, date, lieu, lieuUrl, affiche } = await fetchEvenement(slug)
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 { nom, description, date, lieu, lieuUrl, affiche } = Astro.props;
const Wrapper = lieuUrl ? 'a' : 'div' const Wrapper = lieuUrl ? 'a' : 'div'
--- ---
<Layout> <Layout>
<h1>{nom}</h1> <h1>{nom}</h1>
<div class="content"> <div class="content">
{affiche && <img alt=`Affiche de ${nom}` src={affiche?.fields.file.url} />} {affiche && <img alt=`Affiche de ${nom}` src={affiche?.fields.file.url} />}
<Card title={date}> <Card title={date ? new Date(date as string).toLocaleDateString() : ""}>
<div> <div>
à <Wrapper target="_blank" href={lieuUrl}>{lieu}</Wrapper> à <Wrapper target="_blank" href={lieuUrl}>{lieu}</Wrapper>
</div> </div>
{
<article set:html={description} /> description && <article set:html={documentToHtmlString(description)} />
}
</Card> </Card>
</div> </div>
</Layout> </Layout>