MODIFS CONFIGS : fetch ressources content

This commit is contained in:
2025-03-11 23:53:31 +01:00
parent 2ca44f2550
commit 9093caa557
24 changed files with 281 additions and 164 deletions

View File

@@ -17,8 +17,8 @@ export async function findContentByPath(contentTypes, path) {
};
}
// Handle special case for governance/partners (multiple items per page)
const pageRequested = window.location.href.split('/').pop().replace(/s?$/, '');
// Handle special case for gouvernance, ressources, partenaires (multiple items per page)
let pageRequested = window.location.href.split('/').pop().replace(/s?$/, '');
if (type === pageRequested
|| (type === 'gouvernance' && pageRequested === 'contact')
) {

View File

@@ -1,4 +1,5 @@
import REST from '../../api/rest-axios';
import { getCleanDate } from './contentFetchUtils';
export async function getPartenaires(rawContent) {
const logoPromises = rawContent.map(item =>
@@ -51,4 +52,79 @@ export async function getGouvernance(rawContent) {
);
return await Promise.all(itemPromises);
}
export async function getRessources(rawContent) {
const ressourcesPromises = rawContent.map(item =>
REST.get(item.links.self.href)
.then(async ressourceFetch => {
const partiesPromises = REST.get(item.relationships.field_parties_ressource.links.related.href)
.then(async partiesFetch => {
const parties = partiesFetch.data.data;
const vignettePartie = parties.find(parties => parties.type !== "paragraph--titre_texte");
if (vignettePartie) {
let vignettePromise;
let alt;
switch (vignettePartie.type) {
case 'paragraph--diaporama':
alt = vignettePartie.relationships.field_diaporama.data[0].meta.alt;
vignettePromise = REST.get(vignettePartie.relationships.field_diaporama.links.related.href)
.then(diaporamaFetch => {
return {
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];
vignettePromise = {
url: `https://img.youtube.com/vi/${videoId}/0.jpg`,
alt: item.attributes.title
}
break;
case 'paragraph--galleries':
vignettePromise = REST.get(vignettePartie.relationships.field_gallerie.links.related.href)
.then(gallerieFetch => {
alt = gallerieFetch.data.data.relationships.field_images.data[0].meta.alt;
const galleriePromise = REST.get(gallerieFetch.data.data.relationships.field_images.links.related.href)
.then(gallerieImageFetch => {
return {
url: gallerieImageFetch.data.data[0].attributes.image_style_uri.content_small,
alt
}
});
return galleriePromise;
});
break;
case 'paragraph--document':
alt = vignettePartie.relationships.field_vignette.data.meta.alt;
vignettePromise = REST.get(vignettePartie.relationships.field_vignette.links.related.href)
.then(documentFetch => {
return {
url: documentFetch.data.data.attributes.image_style_uri.content_small,
alt
}
});
break;
default:
vignettePromise = Promise.resolve(null);
}
return vignettePromise;
}
});
return partiesPromises.then(vignette => ({
ressourceType: item.attributes.field_type_de_ressource,
title: item.attributes.title,
auteurice: item.attributes.field_autheurice,
date: getCleanDate(item.attributes.field_date_ressource),
url: ressourceFetch.data.data.attributes.metatag.find(tag => tag.tag === "link")?.attributes.href,
vignette
}));
})
);
return await Promise.all(ressourcesPromises);
}