Skip to content

Commit

Permalink
chore(gatsby-source-contentful): simplify url arg generation (#28440)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz authored Dec 2, 2020
1 parent 013035b commit 297c28b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 297c28b

Please sign in to comment.