Skip to content

Commit 97755c8

Browse files
Changes from Wards review at #35265 (review) (#35475) (#35512)
Co-authored-by: Tyler Barnes <[email protected]>
1 parent 1752f38 commit 97755c8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ const getGatsbyImageCdnFields = async ({
4545
}
4646

4747
const mimeType = node.attributes.filemime
48+
const { filename } = node.attributes
4849

49-
if (!mimeType) {
50+
if (!mimeType || !filename) {
5051
return {}
5152
}
5253

@@ -59,6 +60,7 @@ const getGatsbyImageCdnFields = async ({
5960
if (!mimeType.includes(`image/`)) {
6061
return {
6162
mimeType,
63+
filename,
6264
url,
6365
}
6466
}
@@ -78,6 +80,7 @@ const getGatsbyImageCdnFields = async ({
7880

7981
const hasRequiredData = input => input && input.width && input.height
8082

83+
// extraNodeData comes from the fileNodesExtendedData Map which is built up in sourceNodes in gatsby-node. The data in this Map is found by looking at connections to file nodes from other node types. This is needed because Drupal's JSON API doesn't provide image widths/heights and placeholder urls for file nodes when querying directly for file nodes. This data can only be found on other nodes with relationships to file nodes. In the case that we don't have this data, we use probe-image-size to find the width/height of the image so that image CDN still works even if we don't have the data.
8184
const imageSize = hasRequiredData(extraNodeData)
8285
? extraNodeData
8386
: await probeImageSize(url)
@@ -87,7 +90,7 @@ const getGatsbyImageCdnFields = async ({
8790
}
8891

8992
const gatsbyImageCdnFields = {
90-
filename: node.attributes?.filename,
93+
filename,
9194
url,
9295
placeholderUrl,
9396
width: imageSize.width,

0 commit comments

Comments
 (0)