@@ -223,11 +223,13 @@ exports.mapTagsCategoriesToTaxonomies = entities =>
223223 return e
224224 } )
225225
226- exports . mapElementsToParent = entities => entities . map ( e => {
226+ exports . mapElementsToParent = entities =>
227+ entities . map ( e => {
227228 if ( e . wordpress_parent ) {
228229 // Create parent_element with a link to the parent node of type.
229- e . parent_element___NODE = entities
230- . find ( t => t . wordpress_id === e . wordpress_parent && t . __type === e . __type ) . id
230+ e . parent_element___NODE = entities . find (
231+ t => t . wordpress_id === e . wordpress_parent && t . __type === e . __type
232+ ) . id
231233 }
232234 return e
233235 } )
@@ -278,7 +280,7 @@ exports.searchReplaceContentUrls = function({
278280 } )
279281}
280282
281- exports . mapEntitiesToMedia = entities => {
283+ exports . mapEntitiesToMedia = ( entities , extraMediasRegex ) => {
282284 const media = entities . filter ( e => e . __type === `wordpress__wp_media` )
283285
284286 return entities . map ( e => {
@@ -298,7 +300,11 @@ exports.mapEntitiesToMedia = entities => {
298300 const photoRegex = / \. ( g i f | j p g | j p e g | t i f f | p n g ) $ / i
299301 const isPhotoUrl = filename =>
300302 _ . isString ( filename ) && photoRegex . test ( filename )
301- const isPhotoUrlAlreadyProcessed = key => key == `source_url`
303+ const isOtherMediaUrl = filename =>
304+ _ . isString ( filename ) &&
305+ extraMediasRegex &&
306+ extraMediasRegex . test ( filename )
307+ const isMediaUrlAlreadyProcessed = key => key == `source_url`
302308 const isFeaturedMedia = ( value , key ) =>
303309 ( _ . isNumber ( value ) || _ . isBoolean ( value ) ) && key === `featured_media`
304310 // ACF Gallery and similarly shaped arrays
@@ -319,7 +325,19 @@ exports.mapEntitiesToMedia = entities => {
319325 : null ,
320326 deleteField : true ,
321327 }
322- } else if ( isPhotoUrl ( value ) && ! isPhotoUrlAlreadyProcessed ( key ) ) {
328+ } else if ( isPhotoUrl ( value ) && ! isMediaUrlAlreadyProcessed ( key ) ) {
329+ const mediaNodeID = getMediaItemID (
330+ media . find ( m => m . source_url === value )
331+ )
332+ return {
333+ mediaNodeID,
334+ deleteField : ! ! mediaNodeID ,
335+ }
336+ } else if (
337+ extraMediasRegex &&
338+ isOtherMediaUrl ( value ) &&
339+ ! isMediaUrlAlreadyProcessed ( key )
340+ ) {
323341 const mediaNodeID = getMediaItemID (
324342 media . find ( m => m . source_url === value )
325343 )
0 commit comments