Skip to content

Commit 1853f3b

Browse files
pvdzvladar
andauthored
chore(gatsby-source-contentful): drop last usages of lodash (#28441)
* chore(gatsby-source-contentful): drop last usages of lodash * Update packages/gatsby-source-contentful/src/extend-node-type.js Co-authored-by: Vladimir Razuvaev <[email protected]> Co-authored-by: Vladimir Razuvaev <[email protected]>
1 parent 297c28b commit 1853f3b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

packages/gatsby-source-contentful/src/extend-node-type.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {
1313
} = require(`gatsby/graphql`)
1414
const qs = require(`qs`)
1515
const base64Img = require(`base64-img`)
16-
const _ = require(`lodash`)
1716

1817
const cacheImage = require(`./cache-image`)
1918

@@ -48,9 +47,8 @@ const {
4847
const CONTENTFUL_IMAGE_MAX_SIZE = 4000
4948

5049
const isImage = image =>
51-
_.includes(
52-
[`image/jpeg`, `image/jpg`, `image/png`, `image/webp`, `image/gif`],
53-
_.get(image, `file.contentType`)
50+
[`image/jpeg`, `image/jpg`, `image/png`, `image/webp`, `image/gif`].includes(
51+
image?.file?.contentType
5452
)
5553

5654
const getBase64Image = imageProps => {
@@ -178,11 +176,8 @@ const resolveFixed = (image, options) => {
178176
)
179177
})
180178

181-
// Sort sizes for prettiness.
182-
const sortedSizes = _.sortBy(filteredSizes)
183-
184179
// Create the srcSet.
185-
const srcSet = sortedSizes
180+
const srcSet = filteredSizes
186181
.map((size, i) => {
187182
let resolution
188183
switch (i) {
@@ -286,19 +281,17 @@ const resolveFluid = (image, options) => {
286281

287282
// Add the original image (if it isn't already in there) to ensure the largest image possible
288283
// is available for small images.
284+
const pwidth = parseInt(width, 10)
289285
if (
290-
!filteredSizes.includes(parseInt(width)) &&
291-
parseInt(width) < CONTENTFUL_IMAGE_MAX_SIZE &&
292-
Math.round(width / desiredAspectRatio) < CONTENTFUL_IMAGE_MAX_SIZE
286+
!filteredSizes.includes(pwidth) &&
287+
pwidth < CONTENTFUL_IMAGE_MAX_SIZE &&
288+
Math.round(pwidth / desiredAspectRatio) < CONTENTFUL_IMAGE_MAX_SIZE
293289
) {
294-
filteredSizes.push(width)
290+
filteredSizes.push(pwidth)
295291
}
296292

297-
// Sort sizes for prettiness.
298-
const sortedSizes = _.sortBy(filteredSizes)
299-
300293
// Create the srcSet.
301-
const srcSet = sortedSizes
294+
const srcSet = filteredSizes
302295
.map(width => {
303296
const h = Math.round(width / desiredAspectRatio)
304297
return `${createUrl(image.file.url, {

0 commit comments

Comments
 (0)