avancées centre de ressources
This commit is contained in:
@@ -60,9 +60,85 @@ export async function getRelatedEtape(direction, path) {
|
||||
if (etape.attributes.metatag.some(tag =>
|
||||
tag.tag === "link" && tag.attributes.href === path
|
||||
)) {
|
||||
const relatedEtapeIndex = direction === 'next' ? index + 1 : index - 1;
|
||||
const relatedEtapeIndex = direction ? (direction === 'next' ? index + 1 : index - 1) : index;
|
||||
return getRelatedEtapeContent(allEtapesData.data.data[relatedEtapeIndex]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 parties = partiesFetch.data.data;
|
||||
|
||||
const vignettePartie = parties.find(partie => partie.type !== "paragraph--titre_texte");
|
||||
|
||||
let vignette = null;
|
||||
if (vignettePartie) {
|
||||
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);
|
||||
vignette = {
|
||||
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];
|
||||
vignette = {
|
||||
url: `https://img.youtube.com/vi/${videoId}/0.jpg`,
|
||||
alt: item.attributes.title
|
||||
};
|
||||
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);
|
||||
vignette = {
|
||||
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);
|
||||
vignette = {
|
||||
url: documentFetch.data.data.attributes.image_style_uri.content_small,
|
||||
alt
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
vignette = null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
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
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error fetching resource:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRelatedRessources(etapeId) {
|
||||
const ressources = await REST.get(`/jsonapi/node/ressource/`);
|
||||
const ressourcesRelatedToEtape = ressources.data.data.filter(ressource => ressource.relationships.field_etape.data?.id === etapeId);
|
||||
const ressourcesRelatedPromises = ressourcesRelatedToEtape.map(ressource => getRessourceItemCard(ressource));
|
||||
|
||||
return await Promise.all(ressourcesRelatedPromises);
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import REST from '../../api/rest-axios';
|
||||
import { getCleanDate } from './contentFetchUtils';
|
||||
import { getCleanDate, getRessourceItemCard } from './contentFetchUtils';
|
||||
|
||||
export async function getPartenaires(rawContent) {
|
||||
const logoPromises = rawContent.map(item =>
|
||||
@@ -55,76 +55,7 @@ export async function getGouvernance(rawContent) {
|
||||
}
|
||||
|
||||
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
|
||||
}));
|
||||
})
|
||||
);
|
||||
const ressourcesPromises = rawContent.map(item => getRessourceItemCard(item));
|
||||
|
||||
return await Promise.all(ressourcesPromises);
|
||||
}
|
Reference in New Issue
Block a user