Open olavea opened 1 year ago
@olavea I can work on this issue, can you please provide me some links (for the info which is to be added in the README.md) where can i refer to.
exports.onCreateNode = async gatsbyUtils => {
const { node, actions, createNodeId, createContentDigest } = gatsbyUtils;
const { createNode } = actions;
if (node.internal.type !== 'contentfulGalleryImagesJsonNode') return;
// Create the correct data shape
const cloudinaryAssetData = {
cloudName: 'your-cloud-name',
publicId: node.public_id,
originalHeight: node.height,
originalWidth: node.width,
originalFormat: node.format,
};
// Create a Gatsby node with the correct data shape
createNode({
...cloudinaryAssetData,
id: createNodeId(`contentfulGalleryImagesJsonNode >>> ${node.public_id}`),
parent: node.id,
internal: {
type: 'CloudinaryAsset',
contentDigest: createContentDigest(cloudinaryAssetData),
},
});
};
exports.createSchemaCustomization = async ({ actions }) => {
// Update the schema to add a link to the node with the correct shape
actions.createTypes(`
type contentfulGalleryImagesJsonNode implements Node {
cloudinaryImage: CloudinaryAsset @link(by: "publicId", from: "public_id")
}
`);
};
{
resolve: 'gatsby-transformer-cloudinary',
options: {
transformTypes: ['CloudinaryAsset'],
},
},
query MyQuery {
allContentfulGallery {
nodes {
title
images {
cloudinaryImage {
gatsbyImageData
cloudName
id
originalWidth
originalHeight
originalFormat
}
}
}
}
}
As stated in issue #214, gatsby-transformer-cloudinary does not work with the Sanity Cloudinary Plugin. Not out of the box.
So the README needs a new main headin called "Add Gatsby Image Support to Cloudinary image data sourced from a CMS"
Sanity creates nodes with fields of type
SanityCloudinaryAsset
when you pick an image from Cloudinary. Unfortunately it does not have the shape require by gatsby-transformer-cloudinary.To get around that you may create nodes with the correct shape.
Let say we have the Gatsby node of type
SanityArticle
with a field cover of typeSanityCloudinaryAsset
You may now query for the
gatsbyImageData
on coverImage: