display bad ressources

This commit is contained in:
Valentin Le Moign 2025-06-26 16:13:32 +02:00
parent c2174b27c0
commit c5c1456e80
5 changed files with 23 additions and 24 deletions

View File

@ -135,18 +135,18 @@ export function getVideos(partie) {
export async function getDocument(partie) {
// const documentFetch = await fetchFromRelationships('field_document', partie.relationships);
const uuid = partie.relationships.field_document.data.id;
const uuid = partie.relationships.field_document.data?.id;
const documentFetch = await REST.get(`/jsonapi/file/file/${uuid}`);
const url = documentFetch.data.data.attributes.uri.url;
const url = documentFetch.data.data?.attributes.uri.url;
const titre = partie.attributes.field_titre;
const sousTitre = partie.attributes.field_sous_titre;
const date = partie.attributes.field_date ? getCleanDate(partie.attributes.field_date) : null;
const auteurice = partie.relationships.field_autheurice_s;
const description = partie.relationships.field_document.data.meta.description;
const description = partie.relationships.field_document.data?.meta.description;
const vignetteFetch = await REST.get(`/jsonapi/file/file/${partie.relationships.field_vignette.data.id}`);
const vignette = { url: vignetteFetch.data.data.attributes.image_style_uri.content_small, alt: partie.relationships.field_vignette.data.meta.alt };
const vignetteFetch = await REST.get(`/jsonapi/file/file/${partie.relationships.field_vignette.data?.id}`);
const vignette = { url: vignetteFetch.data.data?.attributes.image_style_uri.content_small, alt: partie.relationships.field_vignette.data?.meta.alt };
return { url, titre, sousTitre, date, auteurice, description, vignette };
}

View File

@ -71,7 +71,7 @@ export async function getRessourceItemCard(item) {
try {
const ressourceFetch = await REST.get(item.links.self.href);
const partiesFetch = await REST.get(item.relationships.field_parties_ressource.links.related.href);
const partiesFetch = await REST.get(item.relationships.field_parties_ressource?.links.related.href);
const parties = partiesFetch.data.data;
const vignettePartie = parties.find(partie => partie.type !== "paragraph--titre_texte");
@ -81,16 +81,16 @@ export async function getRessourceItemCard(item) {
let alt;
switch (vignettePartie.type) {
case 'paragraph--diaporama':
alt = vignettePartie.relationships.field_diaporama.data[0].meta.alt;
const diaporamaFetch = await REST.get(vignettePartie.relationships.field_diaporama.links.related.href);
alt = vignettePartie.relationships.field_diaporama?.data[0]?.meta.alt;
const diaporamaFetch = await REST.get(vignettePartie.relationships.field_diaporama?.links.related.href);
vignette = {
url: diaporamaFetch.data.data[0].attributes.image_style_uri.content_small,
url: diaporamaFetch.data.data[0].attributes.image_style_uri?.content_small,
alt
};
break;
case 'paragraph--video':
const videoId = vignettePartie.attributes.field_videos[0].split('?v=')[1];
const videoId = vignettePartie.attributes.field_videos[0]?.split('?v=')[1];
vignette = {
url: `https://img.youtube.com/vi/${videoId}/0.jpg`,
alt: item.attributes.title
@ -98,20 +98,20 @@ export async function getRessourceItemCard(item) {
break;
case 'paragraph--galleries':
const gallerieFetch = await REST.get(vignettePartie.relationships.field_gallerie.links.related.href);
const galleryAlt = gallerieFetch.data.data.relationships.field_images.data[0].meta.alt;
const gallerieImageFetch = await REST.get(gallerieFetch.data.data.relationships.field_images.links.related.href);
const gallerieFetch = await REST.get(vignettePartie.relationships.field_gallerie?.links.related.href);
const galleryAlt = gallerieFetch.data.data.relationships.field_images?.data[0].meta.alt;
const gallerieImageFetch = await REST.get(gallerieFetch.data.data.relationships.field_images?.links.related.href);
vignette = {
url: gallerieImageFetch.data.data[0].attributes.image_style_uri.content_small,
url: gallerieImageFetch.data.data[0].attributes.image_style_uri?.content_small,
alt: galleryAlt
};
break;
case 'paragraph--document':
alt = vignettePartie.relationships.field_vignette.data.meta.alt;
const documentFetch = await REST.get(vignettePartie.relationships.field_vignette.links.related.href);
alt = vignettePartie.relationships.field_vignette?.data?.meta.alt;
const documentFetch = await REST.get(vignettePartie.relationships.field_vignette?.links.related.href);
vignette = {
url: documentFetch.data.data.attributes.image_style_uri.content_small,
url: documentFetch.data.data?.attributes.image_style_uri?.content_small,
alt
};
break;
@ -130,9 +130,9 @@ export async function getRessourceItemCard(item) {
title: item.attributes.title,
auteurice: item.attributes.field_autheurice,
promoted: item.attributes.field_mis_en_avant,
date: getCleanDate(item.attributes.field_date_ressource),
date: item.attributes.field_date_ressource ? getCleanDate(item.attributes.field_date_ressource) : null,
url: ressourceFetch.data.data.attributes.metatag.find(tag => tag.tag === "link")?.attributes.href,
relatedEtape: relatedEtape.data.data.attributes.title,
relatedEtape: relatedEtape.data.data?.attributes.title,
vignette
};
} catch (error) {

View File

@ -28,7 +28,7 @@ export function fetchSingletonPartialContent(contentType, rawContent) {
if (contentType === 'ressourceItem') {
partialContent.ressourceType = rawContent.attributes.field_type_de_ressource;
partialContent.auteurice = rawContent.attributes.field_autheurice;
partialContent.date = getCleanDate(rawContent.attributes.field_date_ressource);
partialContent.date = rawContent.attributes.field_date_ressource ? getCleanDate(rawContent.attributes.field_date_ressource) : null;
}
return { pageTitle, partialContent };

View File

@ -1,5 +1,5 @@
import REST from '../../api/rest-axios';
import { getCleanDate, getRessourceItemCard } from './contentFetchUtils';
import { getRessourceItemCard } from './contentFetchUtils';
export async function getPartenaires(rawContent) {
const logoPromises = rawContent.map(item =>
@ -55,7 +55,6 @@ export async function getGouvernance(rawContent) {
}
export async function getRessources(rawContent) {
// console.log(rawContent);
const ressourcesPromises = rawContent.map(item => getRessourceItemCard(item));

View File

@ -8,8 +8,8 @@
</figure>
<div>
<h4>{{ ressource.title }}</h4>
<p>Le {{ ressource?.date.d }} {{ ressource?.date.m }} {{ ressource?.date.y }}</p>
<p>Par {{ ressource?.auteurice }}</p>
<p v-if="ressource.date">Le {{ ressource?.date.d }} {{ ressource?.date.m }} {{ ressource?.date.y }}</p>
<p v-if="ressource.auteurice">Par {{ ressource?.auteurice }}</p>
</div>
</div>
</template>