Skip to content

Commit 15a3fbf

Browse files
authored
fix(gatsby-source-drupal): Image cdn fixes (#35619)
* warning spacing * warn about corrupt files and skip over to the next one * Update gatsby-node.js * Only register gatsby image support when skipFileDownloads option is enabled * add [gatsby-source-drupal] to errors
1 parent 6fd8bf7 commit 15a3fbf

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

packages/gatsby-source-drupal/src/gatsby-node.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const {
3030
getExtendedFileNodeData,
3131
} = require(`./utils`)
3232

33+
const imageCdnDocs = `https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`
34+
3335
const agent = {
3436
http: new HttpAgent(),
3537
https: new HttpsAgent(),
@@ -680,12 +682,13 @@ ${JSON.stringify(webhookBody, null, 4)}`
680682
}
681683

682684
if (
685+
skipFileDownloads &&
683686
!imageCDNState.foundPlaceholderStyle &&
684687
!imageCDNState.hasLoggedNoPlaceholderStyle
685688
) {
686689
imageCDNState.hasLoggedNoPlaceholderStyle = true
687690
reporter.warn(
688-
`[gatsby-source-drupal]\nNo Gatsby Image CDN placeholder style found. Please ensure that you have a placeholder style in your Drupal site for the fastest builds. See the docs for more info on gatsby-source-drupal Image CDN support:\n\nhttps://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`
691+
`[gatsby-source-drupal]\nNo Gatsby Image CDN placeholder style found. Please ensure that you have a placeholder style in your Drupal site for the fastest builds. See the docs for more info on gatsby-source-drupal Image CDN support:\n${imageCdnDocs}\n`
689692
)
690693
}
691694

@@ -857,20 +860,29 @@ exports.onCreateDevServer = async ({ app }) => {
857860
polyfillImageServiceDevRoutes(app)
858861
}
859862

860-
exports.createSchemaCustomization = ({ actions, schema }) => {
861-
actions.createTypes([
862-
// polyfill so image CDN works on older versions of Gatsby
863-
addRemoteFilePolyfillInterface(
864-
// this type is merged in with the inferred file__file type, adding Image CDN support via the gatsbyImage GraphQL field. The `RemoteFile` interface as well as the polyfill above are what add the gatsbyImage field.
865-
schema.buildObjectType({
866-
name: `file__file`,
867-
fields: {},
868-
interfaces: [`Node`, `RemoteFile`],
869-
}),
870-
{
871-
schema,
872-
actions,
873-
}
874-
),
875-
])
863+
exports.createSchemaCustomization = (
864+
{ actions, schema, reporter },
865+
pluginOptions
866+
) => {
867+
if (pluginOptions.skipFileDownloads) {
868+
actions.createTypes([
869+
// polyfill so image CDN works on older versions of Gatsby
870+
addRemoteFilePolyfillInterface(
871+
// this type is merged in with the inferred file__file type, adding Image CDN support via the gatsbyImage GraphQL field. The `RemoteFile` interface as well as the polyfill above are what add the gatsbyImage field.
872+
schema.buildObjectType({
873+
name: `file__file`,
874+
fields: {},
875+
interfaces: [`Node`, `RemoteFile`],
876+
}),
877+
{
878+
schema,
879+
actions,
880+
}
881+
),
882+
])
883+
} else {
884+
reporter.info(
885+
`[gatsby-source-drupal] Enable the skipFileDownloads option to use Gatsby's Image CDN. See the docs for more info:\n${imageCdnDocs}\n`
886+
)
887+
}
876888
}

packages/gatsby-source-drupal/src/normalize.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ const getGatsbyImageCdnFields = async ({
100100

101101
return gatsbyImageCdnFields
102102
} catch (e) {
103+
if (e.message.includes(`unrecognized file format`)) {
104+
reporter.error(
105+
`[gatsby-source-drupal] Encountered corrupt file while requesting image dimensions for ${url}`
106+
)
107+
108+
return {}
109+
}
110+
103111
reporter.error(e)
104112
reporter.info(
105113
JSON.stringify(
@@ -113,7 +121,7 @@ const getGatsbyImageCdnFields = async ({
113121
)
114122
)
115123
reporter.panic(
116-
`Encountered an unrecoverable error while generating Gatsby Image CDN fields. See above for additional information.`
124+
`[gatsby-source-drupal] Encountered an unrecoverable error while generating Gatsby Image CDN fields. See above for additional information.`
117125
)
118126
}
119127

0 commit comments

Comments
 (0)