File size: 1,285 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
//Normalizes our data that we get back from Agility CMS
export function normalizePosts(postsFromAgility) {
/* Need an object like this...
- title
- slug
- excerpt
- date
- coverImage
- responsiveImage
- author
- name
- picture
- url
*/
const posts = postsFromAgility.map((p) => {
let normalizedPost = {
title: p.fields.title,
slug: p.fields.slug,
excerpt: p.fields.excerpt,
date: p.fields.date,
content: p.fields.content,
author: p.fields.author
? {
name: p.fields.author.fields.name,
picture: {
url: `${p.fields.author.fields.picture.url}?w=100&h=100`,
},
}
: null,
ogImage: {
url: `${p.fields.coverImage.url}?w=2000&h=1000&q=70`,
},
coverImage: {
responsiveImage: {
srcSet: null,
webpSrcSet: null,
sizes: null,
src: `${p.fields.coverImage.url}?w=2000&h=1000&q=70`,
width: 2000,
height: 1000,
aspectRatio: 100,
base64: null,
alt: p.fields.coverImage.label,
title: null,
bgColor: null,
},
},
};
return normalizedPost;
});
return posts;
}
|