From 297c28ba5a4feab55c824ef999c4834c69652b18 Mon Sep 17 00:00:00 2001 From: Peter van der Zee <209817+pvdz@users.noreply.github.com> Date: Wed, 2 Dec 2020 15:16:40 +0100 Subject: [PATCH] chore(gatsby-source-contentful): simplify url arg generation (#28440) --- .../src/extend-node-type.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/gatsby-source-contentful/src/extend-node-type.js b/packages/gatsby-source-contentful/src/extend-node-type.js index 09319feb70e24..0b3c187718c24 100644 --- a/packages/gatsby-source-contentful/src/extend-node-type.js +++ b/packages/gatsby-source-contentful/src/extend-node-type.js @@ -109,20 +109,19 @@ const getBasicImageProps = (image, args) => { const createUrl = (imgUrl, options = {}) => { // Convert to Contentful names and filter out undefined/null values. - const args = _.pickBy( - { - w: options.width, - h: options.height, - fl: options.jpegProgressive ? `progressive` : null, - q: options.quality, - fm: options.toFormat || ``, - fit: options.resizingBehavior || ``, - f: options.cropFocus || ``, - bg: options.background || ``, - }, - _.identity - ) - return `${imgUrl}?${qs.stringify(args)}` + const urlArgs = { + w: options.width || undefined, + h: options.height || undefined, + fl: options.jpegProgressive ? `progressive` : undefined, + q: options.quality || undefined, + fm: options.toFormat || undefined, + fit: options.resizingBehavior || undefined, + f: options.cropFocus || undefined, + bg: options.background || undefined, + } + + // Note: qs will ignore keys that are `undefined`. `qs.stringify({a: undefined, b: null, c: 1})` => `b=&c=1` + return `${imgUrl}?${qs.stringify(urlArgs)}` } exports.createUrl = createUrl