@@ -3,23 +3,20 @@ const { createRemoteFileNode } = require(`gatsby-source-filesystem`)
3
3
const path = require ( `path` )
4
4
const probeImageSize = require ( `probe-image-size` )
5
5
6
- const { getOptions } = require ( `./plugin-options` )
7
- const getHref = link => {
6
+ import { getOptions } from "./plugin-options"
7
+
8
+ export const getHref = link => {
8
9
if ( typeof link === `object` ) {
9
10
return link . href
10
11
}
11
12
return link
12
13
}
13
14
14
- exports . getHref = getHref
15
-
16
- const imageCDNState = {
15
+ export const imageCDNState = {
17
16
foundPlaceholderStyle : false ,
18
17
hasLoggedNoPlaceholderStyle : false ,
19
18
}
20
19
21
- exports . imageCDNState = imageCDNState
22
-
23
20
let four04WarningCount = 0
24
21
let corruptFileWarningCount = 0
25
22
/**
@@ -142,17 +139,20 @@ const getGatsbyImageCdnFields = async ({
142
139
return { }
143
140
}
144
141
145
- const nodeFromData = async (
142
+ export const nodeFromData = async (
146
143
datum ,
147
144
createNodeId ,
148
145
entityReferenceRevisions = [ ] ,
149
146
pluginOptions ,
150
147
fileNodesExtendedData ,
151
148
reporter
152
149
) => {
153
- const { attributes : { id : attributeId , ...attributes } = { } } = datum
150
+ const { attributes : { id : attributeId , ...attributes } = { id : null } } =
151
+ datum
152
+
154
153
const preservedId =
155
154
typeof attributeId !== `undefined` ? { _attributes_id : attributeId } : { }
155
+
156
156
const langcode = attributes . langcode || `und`
157
157
const type = datum . type . replace ( / - | _ _ | : | \. | \s / g, `_` )
158
158
@@ -164,16 +164,18 @@ const nodeFromData = async (
164
164
reporter,
165
165
} )
166
166
167
+ const versionedId = createNodeIdWithVersion (
168
+ datum . id ,
169
+ datum . type ,
170
+ langcode ,
171
+ attributes . drupal_internal__revision_id ,
172
+ entityReferenceRevisions
173
+ )
174
+
175
+ const gatsbyId = createNodeId ( versionedId )
176
+
167
177
return {
168
- id : createNodeId (
169
- createNodeIdWithVersion (
170
- datum . id ,
171
- datum . type ,
172
- langcode ,
173
- attributes . drupal_internal__revision_id ,
174
- entityReferenceRevisions
175
- )
176
- ) ,
178
+ id : gatsbyId ,
177
179
drupal_id : datum . id ,
178
180
parent : null ,
179
181
drupal_parent_menu_item : attributes . parent ,
@@ -189,52 +191,68 @@ const nodeFromData = async (
189
191
}
190
192
}
191
193
192
- exports . nodeFromData = nodeFromData
193
-
194
194
const isEntityReferenceRevision = ( type , entityReferenceRevisions = [ ] ) =>
195
195
entityReferenceRevisions . findIndex (
196
196
revisionType => type . indexOf ( revisionType ) === 0
197
197
) !== - 1
198
198
199
- const createNodeIdWithVersion = (
200
- id ,
201
- type ,
202
- langcode ,
203
- revisionId ,
199
+ export const createNodeIdWithVersion = (
200
+ id : string ,
201
+ type : string ,
202
+ langcode : string ,
203
+ revisionId : string ,
204
204
entityReferenceRevisions = [ ]
205
205
) => {
206
+ const options = getOptions ( )
207
+
206
208
// Fallback to default language for entities that don't translate.
207
- if ( getOptions ( ) ?. languageConfig ?. nonTranslatableEntities . includes ( type ) ) {
208
- langcode = getOptions ( ) . languageConfig . defaultLanguage
209
+ if (
210
+ options ?. languageConfig ?. nonTranslatableEntities ?. includes ( type ) &&
211
+ options . languageConfig . defaultLanguage
212
+ ) {
213
+ langcode = options . languageConfig . defaultLanguage
209
214
}
210
215
211
216
// If the source plugin hasn't enabled `translation` then always just set langcode
212
217
// to "undefined".
213
- let langcodeNormalized = getOptions ( ) . languageConfig ? langcode : `und`
218
+ let langcodeNormalized = options . languageConfig ? langcode : `und`
219
+
220
+ const renamedCode = options ?. languageConfig ?. renamedEnabledLanguages ?. find (
221
+ lang => lang . langCode === langcodeNormalized
222
+ )
223
+
224
+ if ( renamedCode ) {
225
+ langcodeNormalized = renamedCode . as
226
+ }
214
227
215
228
if (
216
- getOptions ( ) . languageConfig &&
217
- ! getOptions ( ) . languageConfig ?. enabledLanguages . includes ( langcodeNormalized )
229
+ ! renamedCode &&
230
+ options . languageConfig &&
231
+ options . languageConfig . defaultLanguage &&
232
+ ! options ?. languageConfig ?. enabledLanguages ?. includes ( langcodeNormalized )
218
233
) {
219
- langcodeNormalized = getOptions ( ) . languageConfig . defaultLanguage
234
+ langcodeNormalized = options . languageConfig . defaultLanguage
220
235
}
221
236
237
+ const isReferenceRevision = isEntityReferenceRevision (
238
+ type ,
239
+ entityReferenceRevisions
240
+ )
241
+
222
242
// The relationship between an entity and another entity also depends on the revision ID if the field is of type
223
243
// entity reference revision such as for paragraphs.
224
- return isEntityReferenceRevision ( type , entityReferenceRevisions )
244
+ const idVersion = isReferenceRevision
225
245
? `${ langcodeNormalized } .${ id } .${ revisionId || 0 } `
226
246
: `${ langcodeNormalized } .${ id } `
227
- }
228
247
229
- exports . createNodeIdWithVersion = createNodeIdWithVersion
248
+ return idVersion
249
+ }
230
250
231
- const isFileNode = node => {
251
+ export const isFileNode = node => {
232
252
const type = node ?. internal ?. type
233
253
return type === `files` || type === `file__file`
234
254
}
235
255
236
- exports . isFileNode = isFileNode
237
-
238
256
const getFileUrl = ( node , baseUrl ) => {
239
257
let fileUrl = node . url
240
258
@@ -249,8 +267,8 @@ const getFileUrl = (node, baseUrl) => {
249
267
return url
250
268
}
251
269
252
- exports . downloadFile = async (
253
- { node, store , cache, createNode, createNodeId, getCache, reporter } ,
270
+ export const downloadFile = async (
271
+ { node, cache, createNode, createNodeId, getCache } ,
254
272
{ basicAuth, baseUrl }
255
273
) => {
256
274
// handle file downloads
0 commit comments