Skip to content

Commit

Permalink
prevent outputting contentful image url with dimensions greater than …
Browse files Browse the repository at this point in the history
…4000
  • Loading branch information
baseten committed Jan 3, 2018
1 parent 84bfc00 commit 4b6d96f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
const qs = require(`qs`)
const base64Img = require(`base64-img`)
const _ = require(`lodash`)
const maxContentfulImageSize = 4000

const ImageFormatType = new GraphQLEnumType({
name: `ContentfulImageFormat`,
Expand Down Expand Up @@ -130,6 +131,7 @@ const resolveResponsiveResolution = (image, options) => {

// If we're cropping, calculate the specified aspect ratio.
if (options.height) {
options.height = Math.min(options.height, maxContentfulImageSize)
desiredAspectRatio = options.width / options.height
}

Expand All @@ -155,7 +157,7 @@ const resolveResponsiveResolution = (image, options) => {
sizes = sizes.map(Math.round)

// Filter out sizes larger than the image's width.
const filteredSizes = sizes.filter(size => size < width)
const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize)

// Sort sizes for prettiness.
const sortedSizes = _.sortBy(filteredSizes)
Expand Down Expand Up @@ -222,6 +224,7 @@ const resolveResponsiveSizes = (image, options) => {

// If we're cropping, calculate the specified aspect ratio.
if (options.maxHeight) {
options.maxHeight = Math.min(options.maxHeight, maxContentfulImageSize)
desiredAspectRatio = options.maxWidth / options.maxHeight
}

Expand All @@ -248,7 +251,7 @@ const resolveResponsiveSizes = (image, options) => {
sizes = sizes.map(Math.round)

// Filter out sizes larger than the image's maxWidth.
const filteredSizes = sizes.filter(size => size < width)
const filteredSizes = sizes.filter(size => size < width && size < maxContentfulImageSize)

// Add the original image to ensure the largest image possible
// is available for small images.
Expand Down Expand Up @@ -295,6 +298,8 @@ const resolveResize = (image, options) => {
// If the user selected a height (so cropping) and fit option
// is not set, we'll set our defaults
if (options.height) {
options.height = Math.min(options.height, maxContentfulImageSize)

if (!options.resizingBehavior) {
options.resizingBehavior = `fill`
}
Expand Down

0 comments on commit 4b6d96f

Please sign in to comment.