Skip to content

Commit aecbc8d

Browse files
authored
Front card media atom image selection (#14187)
* Update mediaAtom schema to match frontend * Return null if mainImage is an empty string so that the front can still render. * Convert the images array on the video media types to a string. This is because we only ever use the url string downstream. * Refactor mediaAtom image handling by extracting `getLargestImageUrl` helper and replacing inline transformations with reusable logic. * Rename `thumbnailImage` prop to `image` in `LoopVideo` component for consistency and update references accordingly. # Conflicts: # dotcom-rendering/src/components/LoopVideo.importable.tsx * Remove image tranformation as this now happens during the enhancement step * Fix typos * Remove transformation as this happens during the enhancement step * Determine media image during enhancement * Remove override images as we are deciding the image during the enhancement * generate new schemas * Fix types
1 parent ecad67a commit aecbc8d

17 files changed

+96
-302
lines changed

dotcom-rendering/fixtures/manual/trails.ts

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ export const trails: [
9999
height: 288,
100100
origin: 'The Guardian',
101101
expired: false,
102-
images: [
103-
{
104-
url: 'https://i.guim.co.uk/img/media/e060e9b7c92433b3dfeccc98b9206778cda8b8e8/0_180_6680_4009/master/6680.jpg?width=600&quality=45&dpr=2&s=none',
105-
width: 600,
106-
},
107-
],
102+
image: 'https://i.guim.co.uk/img/media/e060e9b7c92433b3dfeccc98b9206778cda8b8e8/0_180_6680_4009/master/6680.jpg?width=600&quality=45&dpr=2&s=none',
108103
},
109104
isExternalLink: false,
110105
showLivePlayable: false,
@@ -465,24 +460,7 @@ export const trails: [
465460
width: 500,
466461
height: 300,
467462
origin: 'The Guardian',
468-
images: [
469-
{
470-
url: 'https://media.guim.co.uk/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/0_0_1920_1080/1000.jpg',
471-
width: 1000,
472-
},
473-
{
474-
url: 'https://media.guim.co.uk/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/0_0_1920_1080/500.jpg',
475-
width: 500,
476-
},
477-
{
478-
url: 'https://media.guim.co.uk/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/0_0_1920_1080/140.jpg',
479-
width: 140,
480-
},
481-
{
482-
url: 'https://media.guim.co.uk/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/0_0_1920_1080/1920.jpg',
483-
width: 1920,
484-
},
485-
],
463+
image: 'https://media.guim.co.uk/13dd7e5c4ca32a53cd22dfd90ac1845ef5e5d643/0_0_1920_1080/1920.jpg',
486464
expired: false,
487465
},
488466
isExternalLink: false,
@@ -608,12 +586,7 @@ export const trails: [
608586
height: 288,
609587
origin: 'The Guardian',
610588
expired: false,
611-
images: [
612-
{
613-
url: 'https://i.guim.co.uk/img/media/e060e9b7c92433b3dfeccc98b9206778cda8b8e8/0_180_6680_4009/master/6680.jpg?width=600&quality=45&dpr=2&s=none',
614-
width: 600,
615-
},
616-
],
589+
image: 'https://i.guim.co.uk/img/media/e060e9b7c92433b3dfeccc98b9206778cda8b8e8/0_180_6680_4009/master/6680.jpg?width=600&quality=45&dpr=2&s=none',
617590
},
618591
isExternalLink: false,
619592
showLivePlayable: false,
@@ -794,28 +767,7 @@ export const videoTrails: [DCRFrontCard, DCRFrontCard] = [
794767
height: 300,
795768
origin: 'SNTV',
796769
expired: false,
797-
images: [
798-
{
799-
url: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/2000.jpg',
800-
width: 2000,
801-
},
802-
{
803-
url: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/1000.jpg',
804-
width: 1000,
805-
},
806-
{
807-
url: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/500.jpg',
808-
width: 500,
809-
},
810-
{
811-
url: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/140.jpg',
812-
width: 140,
813-
},
814-
{
815-
url: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/3000.jpg',
816-
width: 3000,
817-
},
818-
],
770+
image: 'https://media.guim.co.uk/0cab2d745b3423b0fac318c9ee09b79678f568f8/0_56_3000_1688/3000.jpg',
819771
},
820772
showVideo: true,
821773
image: {
@@ -849,28 +801,7 @@ export const videoTrails: [DCRFrontCard, DCRFrontCard] = [
849801
height: 300,
850802
origin: 'Reuters',
851803
expired: false,
852-
images: [
853-
{
854-
url: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/2000.jpg',
855-
width: 2000,
856-
},
857-
{
858-
url: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/1000.jpg',
859-
width: 1000,
860-
},
861-
{
862-
url: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/500.jpg',
863-
width: 500,
864-
},
865-
{
866-
url: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/140.jpg',
867-
width: 140,
868-
},
869-
{
870-
url: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/5358.jpg',
871-
width: 5358,
872-
},
873-
],
804+
image: 'https://media.guim.co.uk/908aa315f66a09bc6ea607b6049cd72decd2dfa6/0_0_5358_3014/5358.jpg',
874805
},
875806
showVideo: true,
876807
image: {

dotcom-rendering/src/components/Card/Card.stories.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ const mainVideo: MainMedia = {
6464
title: '’I care, but I don’t care’: Life after the Queen’s death | Anywhere but Westminster',
6565
expired: false,
6666
duration: 200,
67-
images: [480, 640, 960, 1024, 1200].map((width) => ({
68-
url: `https://i.guim.co.uk/img/media/2eb01d138eb8fba6e59ce7589a60e3ff984f6a7a/0_0_1920_1080/1920.jpg?width=${width}&quality=45&dpr=2&s=none`,
69-
width,
70-
})),
67+
image: `https://i.guim.co.uk/img/media/2eb01d138eb8fba6e59ce7589a60e3ff984f6a7a/0_0_1920_1080/1920.jpg?width=1200&quality=45&dpr=2&s=none`,
7168
width: 480,
7269
height: 288,
7370
origin: 'The Guardian',

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,12 @@ const getMedia = ({
265265
return {
266266
type: 'loop-video',
267267
mainMedia,
268-
...(imageUrl && { imageUrl }),
269268
} as const;
270269
}
271270
if (mainMedia?.type === 'Video' && canPlayInline) {
272271
return {
273272
type: 'video',
274273
mainMedia,
275-
...(imageUrl && { imageUrl }),
276274
} as const;
277275
}
278276
if (slideshowImages) return { type: 'slideshow', slideshowImages } as const;
@@ -904,12 +902,12 @@ export const Card = ({
904902
src={media.mainMedia.videoId}
905903
height={media.mainMedia.height}
906904
width={media.mainMedia.width}
907-
thumbnailImage={
908-
media.mainMedia.thumbnailImage ?? ''
909-
}
905+
image={media.mainMedia.image ?? ''}
910906
fallbackImageComponent={
911907
<CardPicture
912-
mainImage={media.imageUrl ?? ''}
908+
mainImage={
909+
media.mainMedia.image ?? ''
910+
}
913911
imageSize={imageSize}
914912
loading={imageLoading}
915913
alt={media.imageAltText}
@@ -952,9 +950,8 @@ export const Card = ({
952950
.duration
953951
}
954952
posterImage={
955-
media.mainMedia.images
953+
media.mainMedia.image
956954
}
957-
overrideImage={media.imageUrl}
958955
width={media.mainMedia.width}
959956
height={media.mainMedia.height}
960957
origin={media.mainMedia.origin}
@@ -1013,15 +1010,7 @@ export const Card = ({
10131010
<div>
10141011
<CardPicture
10151012
mainImage={
1016-
media.imageUrl
1017-
? media.imageUrl
1018-
: media.mainMedia.images.reduce(
1019-
(prev, current) =>
1020-
prev.width >
1021-
current.width
1022-
? prev
1023-
: current,
1024-
).url
1013+
media.mainMedia.image ?? ''
10251014
}
10261015
imageSize={imageSize}
10271016
alt={headlineText}

dotcom-rendering/src/components/CardPicture.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ export const CardPicture = ({
203203
aspectRatio = '5:3',
204204
mobileAspectRatio,
205205
}: Props) => {
206+
if (mainImage === '') {
207+
return null;
208+
}
206209
const sources = generateSources(
207210
mainImage,
208211
decideImageWidths(imageSize, aspectRatio),

dotcom-rendering/src/components/FeatureCard.stories.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,7 @@ export const Video: Story = {
258258
title: 'Video Title',
259259
duration: 120,
260260
expired: false,
261-
images: [
262-
{
263-
url: 'https://media.guim.co.uk/video-thumbnail.jpg',
264-
width: 1920,
265-
},
266-
],
261+
image: 'https://media.guim.co.uk/video-thumbnail.jpg',
267262
},
268263
},
269264
};

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ const getMedia = ({
238238
return {
239239
type: 'video',
240240
mainMedia,
241-
...(imageUrl && { imageUrl }),
242241
} as const;
243242
}
244243

@@ -430,8 +429,7 @@ export const FeatureCard = ({
430429
stickyVideos={false}
431430
enableAds={false}
432431
duration={mainMedia.duration}
433-
posterImage={mainMedia.images}
434-
overrideImage={media?.imageUrl}
432+
posterImage={mainMedia.image}
435433
width={300}
436434
height={375}
437435
origin="The Guardian"
@@ -479,15 +477,7 @@ export const FeatureCard = ({
479477
<div>
480478
<CardPicture
481479
mainImage={
482-
media.imageUrl
483-
? media.imageUrl
484-
: media.mainMedia.images.reduce(
485-
(prev, current) =>
486-
prev.width >
487-
current.width
488-
? prev
489-
: current,
490-
).url
480+
media.mainMedia.image ?? ''
491481
}
492482
imageSize={imageSize}
493483
alt={headlineText}

dotcom-rendering/src/components/FlexibleGeneral.stories.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,7 @@ const liveUpdatesCard = {
259259
title: 'Spain fans celebrate at final whistle as England fans left heartbroken – video',
260260
duration: 0,
261261
expired: false,
262-
images: [
263-
{
264-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/2000.jpg',
265-
width: 2000,
266-
},
267-
{
268-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/1000.jpg',
269-
width: 1000,
270-
},
271-
{
272-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/500.jpg',
273-
width: 500,
274-
},
275-
{
276-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/140.jpg',
277-
width: 140,
278-
},
279-
{
280-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/4791.jpg',
281-
width: 4791,
282-
},
283-
],
262+
image: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/4791.jpg',
284263
},
285264
isExternalLink: false,
286265
discussionApiUrl,

dotcom-rendering/src/components/FlexibleSpecial.stories.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,7 @@ const liveUpdatesCard = {
5454
title: 'Spain fans celebrate at final whistle as England fans left heartbroken – video',
5555
duration: 0,
5656
expired: false,
57-
images: [
58-
{
59-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/2000.jpg',
60-
width: 2000,
61-
},
62-
{
63-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/1000.jpg',
64-
width: 1000,
65-
},
66-
{
67-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/500.jpg',
68-
width: 500,
69-
},
70-
{
71-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/140.jpg',
72-
width: 140,
73-
},
74-
{
75-
url: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/4791.jpg',
76-
width: 4791,
77-
},
78-
],
57+
image: 'https://media.guim.co.uk/68333e95233d9c68b32b56c12205c5ded94dfbf8/0_117_4791_2696/4791.jpg',
7958
},
8059
isExternalLink: false,
8160
discussionApiUrl,

dotcom-rendering/src/components/LoopVideo.importable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Props = {
3636
uniqueId: string;
3737
width: number;
3838
height: number;
39-
thumbnailImage: string;
39+
image: string;
4040
fallbackImageComponent: JSX.Element;
4141
};
4242

@@ -45,7 +45,7 @@ export const LoopVideo = ({
4545
uniqueId,
4646
width,
4747
height,
48-
thumbnailImage,
48+
image,
4949
fallbackImageComponent,
5050
}: Props) => {
5151
const adapted = useShouldAdapt();
@@ -217,9 +217,9 @@ export const LoopVideo = ({
217217
isAutoplayAllowed === false ||
218218
(isInView === false && !hasBeenInView)
219219
) {
220-
setPosterImage(thumbnailImage);
220+
setPosterImage(image);
221221
}
222-
}, [isAutoplayAllowed, isInView, hasBeenInView, thumbnailImage]);
222+
}, [isAutoplayAllowed, isInView, hasBeenInView, image]);
223223

224224
/**
225225
* We almost always want to preload some of the video data. If a user has prefers-reduced-motion

dotcom-rendering/src/components/LoopVideo.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export const Default = {
2323
uniqueId: 'test-video-1',
2424
height: 720,
2525
width: 900,
26-
thumbnailImage:
27-
'https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg',
26+
image: 'https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg',
2827
fallbackImageComponent: (
2928
<CardPicture
3029
mainImage="https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg"

0 commit comments

Comments
 (0)