Skip to content

Commit 07cd67d

Browse files
committed
Use dimensions from video assets
1 parent 08835be commit 07cd67d

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { ArticleFormat } from '../lib/articleFormat';
2-
import { convertAssetsToVideoSources, getSubtitleAsset } from '../lib/video';
2+
import {
3+
convertAssetsToVideoSources,
4+
getFirstVideoAsset,
5+
getSubtitleAsset,
6+
} from '../lib/video';
37
import type { MediaAtomBlockElement } from '../types/content';
48
import { Caption } from './Caption';
59
import { SelfHostedVideo } from './SelfHostedVideo.importable';
@@ -17,6 +21,7 @@ export const LoopVideoInArticle = ({
1721
}: LoopVideoInArticleProps) => {
1822
const posterImageUrl = element.posterImage?.[0]?.url;
1923
const caption = element.title;
24+
const firstVideoAsset = getFirstVideoAsset(element.assets);
2025

2126
if (!posterImageUrl) {
2227
return null;
@@ -28,18 +33,18 @@ export const LoopVideoInArticle = ({
2833
atomId={element.id}
2934
fallbackImage={posterImageUrl}
3035
fallbackImageAlt={caption}
31-
fallbackImageAspectRatio="5:4"
36+
fallbackImageAspectRatio={firstVideoAsset?.aspectRatio ?? '5:4'}
3237
fallbackImageLoading="lazy"
3338
fallbackImageSize="small"
34-
height={400}
39+
height={firstVideoAsset?.dimensions?.height ?? 400}
3540
linkTo="Article-embed-MediaAtomBlockElement"
3641
posterImage={posterImageUrl}
3742
sources={convertAssetsToVideoSources(element.assets)}
3843
subtitleSize="medium"
3944
subtitleSource={getSubtitleAsset(element.assets)}
4045
videoStyle="Loop"
4146
uniqueId={element.id}
42-
width={500}
47+
width={firstVideoAsset?.dimensions?.width ?? 500}
4348
/>
4449
{!!caption && (
4550
<Caption

dotcom-rendering/src/frontend/schemas/feArticle.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,24 @@
21102110
"mimeType": {
21112111
"type": "string"
21122112
},
2113+
"dimensions": {
2114+
"type": "object",
2115+
"properties": {
2116+
"width": {
2117+
"type": "number"
2118+
},
2119+
"height": {
2120+
"type": "number"
2121+
}
2122+
},
2123+
"required": [
2124+
"height",
2125+
"width"
2126+
]
2127+
},
2128+
"aspectRatio": {
2129+
"type": "string"
2130+
},
21132131
"fields": {
21142132
"type": "object",
21152133
"properties": {

dotcom-rendering/src/lib/video.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ export const convertAssetsToVideoSources = (assets: VideoAssets[]): Source[] =>
4949

5050
export const getSubtitleAsset = (assets: VideoAssets[]): string | undefined =>
5151
assets.find((asset) => asset.mimeType === 'text/vtt')?.url;
52+
53+
export const getFirstVideoAsset = (
54+
assets: VideoAssets[],
55+
): VideoAssets | undefined => {
56+
return assets.find((asset) => isSupportedMimeType(asset.mimeType));
57+
};

dotcom-rendering/src/model/block-schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,24 @@
15981598
"mimeType": {
15991599
"type": "string"
16001600
},
1601+
"dimensions": {
1602+
"type": "object",
1603+
"properties": {
1604+
"width": {
1605+
"type": "number"
1606+
},
1607+
"height": {
1608+
"type": "number"
1609+
}
1610+
},
1611+
"required": [
1612+
"height",
1613+
"width"
1614+
]
1615+
},
1616+
"aspectRatio": {
1617+
"type": "string"
1618+
},
16011619
"fields": {
16021620
"type": "object",
16031621
"properties": {

dotcom-rendering/src/types/content.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,11 @@ export interface Image {
944944
export interface VideoAssets {
945945
url: string;
946946
mimeType?: string;
947+
dimensions?: {
948+
width: number;
949+
height: number;
950+
};
951+
aspectRatio?: string;
947952
fields?: {
948953
source?: string;
949954
embeddable?: string;

0 commit comments

Comments
 (0)