Skip to content

Commit 5598c5d

Browse files
committed
use lowres images
1 parent 1363d85 commit 5598c5d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/components/design-library-list/use-preview-renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
addPlaceholderForPostsBlock, cleanParse,
1010
parseDisabledBlocks, adjustPatternSpacing,
1111
replacePlaceholders,
12+
replaceImages,
1213
} from './util'
1314

1415
/**
@@ -165,6 +166,8 @@ export const usePreviewRenderer = (
165166
)
166167
}
167168

169+
preview = replaceImages( preview )
170+
168171
const cleanedBlock = preview.replace( /<!--[\s\S]*?-->/g, '' ) // removes comment
169172

170173
setBlocks( {

src/components/design-library-list/util.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ export const addPlaceholderForPostsBlock = ( content, postsPlaceholder, defaultV
290290
} )
291291
}
292292

293+
export const replaceImages = content => {
294+
const NEW_IMAGE_STORAGE = cdnUrl.replace( /\/$/, '' ) + '/library-v4/images/low-resolution/'
295+
296+
// Replace images in the content with low resolution images from the new image storage
297+
return content.replace(
298+
new RegExp( IMAGE_STORAGE.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ) + '([^\\/\\s]+)\\.(jpeg|jpg|png)', 'g' ),
299+
( match, filename, ext ) => {
300+
let newExt = ext
301+
if ( ext === 'jpeg' || ext === 'jpg' ) {
302+
newExt = 'jpg'
303+
} else if ( ext === 'png' ) {
304+
newExt = 'png'
305+
}
306+
return NEW_IMAGE_STORAGE + filename + '.' + newExt
307+
}
308+
)
309+
}
310+
293311
// Additional styles for blocks to render properly in the preview
294312
export const getAdditionalStylesForPreview = () => {
295313
let styles = ''

0 commit comments

Comments
 (0)