fix: pages évènements vides
parent
502131f3ab
commit
a718a3ae80
|
@ -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]!)
|
||||||
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue