Files
posthog.com/plugins/gatsby-transformer-cloudinary/node-creation/create-image-node.js
2024-09-12 15:33:50 -07:00

49 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const stringify = require('fast-json-stable-stringify');
const { getPluginOptions } = require('../options');
exports.createImageNode = ({
cloudinaryUploadResult,
parentNode,
createContentDigest,
createNodeId,
cloudName,
defaultBase64,
defaultTracedSVG,
}) => {
const { public_id, height, width, version, format } = cloudinaryUploadResult;
const fingerprint = stringify({
cloudName,
height,
public_id,
version,
width,
});
const imageNode = {
// These helper fields are only here so the resolvers have access to them.
// They will *not* be available via Gatsbys data layer.
cloudName: cloudName || getPluginOptions().cloudName,
publicId: public_id,
version: version,
originalHeight: height,
originalWidth: width,
originalFormat: format,
rawCloudinaryData: cloudinaryUploadResult,
defaultBase64,
defaultTracedSVG,
// Add the required internal Gatsby node fields.
id: createNodeId(`CloudinaryAsset-${fingerprint}`),
parent: parentNode.id,
internal: {
type: 'CloudinaryAsset',
// Gatsby uses the content digest to decide when to reprocess a given
// node. We can use the Cloudinary URL to avoid doing extra work.
contentDigest: createContentDigest(cloudinaryUploadResult),
},
};
return imageNode;
};