Skip to content

Commit df1586d

Browse files
committed
webp final using images API
1 parent 42c9ad1 commit df1586d

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/shared/components/Contentful/Image/Image.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ export class ImageInner extends React.Component {
7373
clipSvg,
7474
animation,
7575
} = this.props;
76-
77-
// const imageUrl = _.get(imageSources.source, 'file.url');
78-
// const contentType = _.get(imageSources, 'file.contentType');
7976
const clipSvgUrl = _.get(clipSvg, 'file.url');
8077
const imgStyle = image.extraStylesForImage ? fixStyle(image.extraStylesForImage) : {};
8178
if (clipSvgUrl) {
@@ -99,11 +96,11 @@ export class ImageInner extends React.Component {
9996
{
10097
animation.animateOnScroll ? (
10198
<picture>
102-
<source srcSet={imageSources.source.file.url} type={imageSources.source.file.contentType} media={imageSources.sourceMobile ? '(min-width: 769px)' : null} />
103-
{ imageSources.sourceMobile && <source srcSet={imageSources.sourceMobile.file.url} type={imageSources.sourceMobile.file.contentType} media="(max-width: 768px)" /> }
104-
{ imageSources.sourcePolyfillMobile && <source srcSet={imageSources.sourcePolyfillMobile.file.url} type={imageSources.sourcePolyfillMobile.file.contentType} media="(max-width: 768px)" /> }
99+
<source srcSet={imageSources.source.file.url} type={imageSources.source.file.contentType} media="(min-width: 769px)" />
100+
{ imageSources.sourceMobile && <source srcSet={`${imageSources.sourceMobile.file.url}?w=768`} type={imageSources.sourceMobile.file.contentType} media="(max-width: 768px)" /> }
101+
<source srcSet={`${imageSources.source.file.url}?w=768`} type={imageSources.source.file.contentType} media="(max-width: 768px)" />
105102
<img
106-
src={imageSources.sourcePolyfill ? imageSources.sourcePolyfill.file.url : imageSources.source.file.url}
103+
src={`${imageSources.source.file.url}?fm=png`}
107104
alt={image.alt || image.name}
108105
style={imgStyle}
109106
data-aos={animation.animateOnScroll}
@@ -119,11 +116,11 @@ export class ImageInner extends React.Component {
119116
</picture>
120117
) : (
121118
<picture>
122-
<source srcSet={imageSources.source.file.url} type={imageSources.source.file.contentType} media={imageSources.sourceMobile ? '(min-width: 769px)' : null} />
123-
{ imageSources.sourceMobile && <source srcSet={imageSources.sourceMobile.file.url} type={imageSources.sourceMobile.file.contentType} media="(max-width: 768px)" /> }
124-
{ imageSources.sourcePolyfillMobile && <source srcSet={imageSources.sourcePolyfillMobile.file.url} type={imageSources.sourcePolyfillMobile.file.contentType} media="(max-width: 768px)" /> }
119+
<source srcSet={imageSources.source.file.url} type={imageSources.source.file.contentType} media="(min-width: 769px)" />
120+
{ imageSources.sourceMobile && <source srcSet={`${imageSources.sourceMobile.file.url}?w=768`} type={imageSources.sourceMobile.file.contentType} media="(max-width: 768px)" /> }
121+
<source srcSet={`${imageSources.source.file.url}?w=768`} type={imageSources.source.file.contentType} media="(max-width: 768px)" />
125122
<img
126-
src={imageSources.sourcePolyfill ? imageSources.sourcePolyfill.file.url : imageSources.source.file.url}
123+
src={`${imageSources.source.file.url}?fm=png`}
127124
alt={image.alt || image.name}
128125
style={imgStyle}
129126
loading="lazy"

src/shared/components/Contentful/Image/index.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ export default function ImageLoader(props) {
2828
const { fields } = data.entries.items[id];
2929
const imgId = _.get(fields, 'source.sys.id');
3030
const imgIdMobile = _.get(fields, 'sourceMobile.sys.id');
31-
const imgIdPolyfill = _.get(fields, 'sourcePolyfill.sys.id');
32-
const imgIdPolyfillMobile = _.get(fields, 'sourceMobilePolyfill.sys.id');
3331
const clipSvgId = _.get(fields, 'clipSvg.sys.id');
3432
const assetIds = _.compact(
35-
[imgId, imgIdMobile, imgIdPolyfill, imgIdPolyfillMobile, clipSvgId],
33+
[imgId, imgIdMobile, clipSvgId],
3634
);
3735
const animationId = _.get(fields, 'animationOnScroll.sys.id');
3836
const entryIds = [];
@@ -53,8 +51,6 @@ export default function ImageLoader(props) {
5351
const imageSources = {
5452
source: _.get(items, [imgId, 'fields']),
5553
sourceMobile: _.get(items, [imgIdMobile, 'fields']),
56-
sourcePolyfill: _.get(items, [imgIdPolyfill, 'fields']),
57-
sourcePolyfillMobile: _.get(items, [imgIdPolyfillMobile, 'fields']),
5854
};
5955
let animation = {};
6056
if (animationId) {

0 commit comments

Comments
 (0)