-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(gatsby-source-contentful): drop last usages of lodash #28441
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`) | ||
|
||
|
@@ -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 => { | ||
|
@@ -178,11 +176,8 @@ const resolveFixed = (image, options) => { | |
) | ||
}) | ||
|
||
// Sort sizes for prettiness. | ||
const sortedSizes = _.sortBy(filteredSizes) | ||
|
||
// Create the srcSet. | ||
pvdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const srcSet = sortedSizes | ||
const srcSet = filteredSizes | ||
.map((size, i) => { | ||
let resolution | ||
switch (i) { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sort is similar to above except the condition before it does not exist in the other case. The condition will only add the current width if it doesn't already exist here. And the loop before will cull any widths that are greater than this width. So either way, the width should be the last element in the list. This means the |
||
|
||
// Create the srcSet. | ||
pvdz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const srcSet = sortedSizes | ||
const srcSet = filteredSizes | ||
.map(width => { | ||
const h = Math.round(width / desiredAspectRatio) | ||
return `${createUrl(image.file.url, { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array is initialized ordered. It is only pruned, not shuffled / added. So this sort should be a noop in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warrants a comment that
fixedSizes
is expected to be sorted in the first place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure