From 298eb317f91b050f822803934931c136fa4e94c1 Mon Sep 17 00:00:00 2001 From: Max Stoiber Date: Mon, 25 Jan 2021 16:36:53 +0100 Subject: [PATCH] fix(gatsby-plugin-sharp): ignore incorrect duotone options (#28999) * fix(gatsby-plugin-sharp): ignore incorrect duotone options * Update packages/gatsby-plugin-sharp/src/index.js Co-authored-by: Matt Kane * Update index.js * add warning for invalid duotone options Co-authored-by: Matt Kane Co-authored-by: Laurie --- packages/gatsby-plugin-sharp/src/image-data.ts | 8 ++++++++ packages/gatsby-plugin-sharp/src/index.js | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-sharp/src/image-data.ts b/packages/gatsby-plugin-sharp/src/image-data.ts index b95eb02214e28..7c46add364945 100644 --- a/packages/gatsby-plugin-sharp/src/image-data.ts +++ b/packages/gatsby-plugin-sharp/src/image-data.ts @@ -13,6 +13,7 @@ const DEFAULT_BLURRED_IMAGE_WIDTH = 20 const DEFAULT_BREAKPOINTS = [750, 1080, 1366, 1920] type ImageFormat = "jpg" | "png" | "webp" | "avif" | "" | "auto" + export type FileNode = Node & { absolutePath?: string extension: string @@ -114,8 +115,15 @@ export async function generateImageData({ const { fit = `cover`, cropFocus = sharp.strategy.attention, + duotone, } = transformOptions + if (duotone && (!duotone.highlight || !duotone.shadow)) { + reporter.warn( + `Invalid duotone option specified for ${file.absolutePath}, ignoring. Please pass an object to duotone with the keys "highlight" and "shadow" set to the corresponding hex values you want to use.` + ) + } + const metadata = await getImageMetadata(file, placeholder === `dominantColor`) if ((args.width || args.height) && layout === `fullWidth`) { diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 3536017a7b447..6a6cd286a6c51 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -329,7 +329,13 @@ async function generateBase64({ file, args = {}, reporter }) { // duotone if (options.duotone) { - pipeline = await duotone(options.duotone, options.toFormat, pipeline) + if (options.duotone.highlight && options.duotone.shadow) { + pipeline = await duotone(options.duotone, options.toFormat, pipeline) + } else { + reporter.warn( + `Invalid duotone option specified for ${file.absolutePath}, ignoring. Please pass an object to duotone with the keys "highlight" and "shadow" set to the corresponding hex values you want to use.` + ) + } } let buffer let info