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)
.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 { 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'
---
<Layout>
<h1>{nom}</h1>
<div class="content">
{affiche && <img alt=`Affiche de ${nom}` src={affiche?.fields.file.url} />}
<Card title={date}>
<Card title={date ? new Date(date as string).toLocaleDateString() : ""}>
<div>
à <Wrapper target="_blank" href={lieuUrl}>{lieu}</Wrapper>
</div>
<article set:html={description} />
{
description && <article set:html={documentToHtmlString(description)} />
}
</Card>
</div>
</Layout>