Skip to content

Commit

Permalink
chore(gatsby-source-contentful): drop last usages of lodash (#28441)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pvdz and vladar authored Dec 2, 2020
1 parent 297c28b commit 1853f3b
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
} = require(`gatsby/graphql`)
const qs = require(`qs`)
const base64Img = require(`base64-img`)
const _ = require(`lodash`)

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

Expand Down Expand Up @@ -48,9 +47,8 @@ const {
const CONTENTFUL_IMAGE_MAX_SIZE = 4000

const isImage = image =>
_.includes(
[`image/jpeg`, `image/jpg`, `image/png`, `image/webp`, `image/gif`],
_.get(image, `file.contentType`)
[`image/jpeg`, `image/jpg`, `image/png`, `image/webp`, `image/gif`].includes(
image?.file?.contentType
)

const getBase64Image = imageProps => {
Expand Down Expand Up @@ -178,11 +176,8 @@ const resolveFixed = (image, options) => {
)
})

// Sort sizes for prettiness.
const sortedSizes = _.sortBy(filteredSizes)

// Create the srcSet.
const srcSet = sortedSizes
const srcSet = filteredSizes
.map((size, i) => {
let resolution
switch (i) {
Expand Down Expand Up @@ -286,19 +281,17 @@ const resolveFluid = (image, options) => {

// Add the original image (if it isn't already in there) to ensure the largest image possible
// is available for small images.
const pwidth = parseInt(width, 10)
if (
!filteredSizes.includes(parseInt(width)) &&
parseInt(width) < CONTENTFUL_IMAGE_MAX_SIZE &&
Math.round(width / desiredAspectRatio) < CONTENTFUL_IMAGE_MAX_SIZE
!filteredSizes.includes(pwidth) &&
pwidth < CONTENTFUL_IMAGE_MAX_SIZE &&
Math.round(pwidth / desiredAspectRatio) < CONTENTFUL_IMAGE_MAX_SIZE
) {
filteredSizes.push(width)
filteredSizes.push(pwidth)
}

// Sort sizes for prettiness.
const sortedSizes = _.sortBy(filteredSizes)

// Create the srcSet.
const srcSet = sortedSizes
const srcSet = filteredSizes
.map(width => {
const h = Math.round(width / desiredAspectRatio)
return `${createUrl(image.file.url, {
Expand Down

0 comments on commit 1853f3b

Please sign in to comment.