avancées centre de ressource

This commit is contained in:
2025-03-26 00:28:41 +01:00
parent 9093caa557
commit a1916e3219
14 changed files with 670 additions and 30 deletions

View File

@ -1,5 +1,5 @@
import REST from '../../api/rest-axios';
import { fetchFromRelationships } from './contentFetchUtils';
import { fetchFromRelationships, getCleanDate } from './contentFetchUtils';
export async function getCarteSensible(partie) {
@ -131,4 +131,46 @@ export function getVideos(partie) {
videos.push(videoUrl);
}
return videos;
}
export async function getDocument(partie) {
// const documentFetch = await fetchFromRelationships('field_document', partie.relationships);
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 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 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 };
}
export async function getGallerie(partie) {
const gallerieFetch = await fetchFromRelationships('field_gallerie', partie.relationships);
if (gallerieFetch) {
const titre = gallerieFetch.attributes.title;
const introduction = gallerieFetch.attributes.body?.processed;
const imagesFetch = await fetchFromRelationships('field_images', gallerieFetch.relationships);
let images = [];
imagesFetch.forEach((image, index) => {
images.push({
url: {
original: image.attributes.uri.url,
small: image.attributes.image_style_uri.content_small,
medium: image.attributes.image_style_uri.content_medium,
large: image.attributes.image_style_uri.content_large,
},
alt: gallerieFetch.relationships.field_images.data[index].meta.alt,
});
});
return { titre, introduction, images };
}
}

View File

@ -3,7 +3,7 @@ import REST from '../../api/rest-axios';
export async function fetchFromRelationships(field, relationships) {
field = relationships[field] ? field : `${field}_static`;
if (relationships[field].links) {
if (relationships[field]?.links) {
const contentLink = relationships[field].links.related.href;
return REST.get(contentLink)
.then(contentFetch => contentFetch.data.data)

View File

@ -10,9 +10,9 @@ export async function findContentByPath(contentTypes, path) {
)
);
if (content) {
if (content) {
return {
contentType: type,
contentType: content.type === 'node--ressource' ? 'ressourceItem' : type,
rawContent: content,
};
}