Skip to content

Commit

Permalink
Add thumbnail image to audio page (#12459)
Browse files Browse the repository at this point in the history
Added image to the blocks for audio articles and where the audio image is present.
  • Loading branch information
oliverabrahams authored Oct 14, 2024
1 parent ea365ac commit 7bfc4ed
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
4 changes: 3 additions & 1 deletion dotcom-rendering/src/model/article-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@
"starRating": {
"$ref": "#/definitions/StarRating"
},
"audioArticleImage": {
"$ref": "#/definitions/ImageBlockElement"
},
"trailText": {
"type": "string"
},
Expand Down Expand Up @@ -1480,7 +1483,6 @@
"fields",
"index",
"mediaType",
"mimeType",
"url"
]
},
Expand Down
1 change: 0 additions & 1 deletion dotcom-rendering/src/model/block-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,6 @@
"fields",
"index",
"mediaType",
"mimeType",
"url"
]
},
Expand Down
23 changes: 19 additions & 4 deletions dotcom-rendering/src/model/enhanceBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { isUndefined } from '@guardian/libs';
import { type ArticleFormat } from '../lib/format';
import type { FEElement, ImageForLightbox, Newsletter } from '../types/content';
import type {
FEElement,
ImageBlockElement,
ImageForLightbox,
Newsletter,
} from '../types/content';
import type { RenderingTarget } from '../types/renderingTarget';
import { enhanceAdPlaceholders } from './enhance-ad-placeholders';
import { enhanceBlockquotes } from './enhance-blockquotes';
Expand All @@ -23,6 +28,7 @@ type Options = {
promotedNewsletter: Newsletter | undefined;
imagesForLightbox: ImageForLightbox[];
hasAffiliateLinksDisclaimer: boolean;
audioArticleImage?: ImageBlockElement;
};

const enhanceNewsletterSignup =
Expand Down Expand Up @@ -92,8 +98,17 @@ export const enhanceBlocks = (
blocks: Block[],
format: ArticleFormat,
options: Options,
): Block[] =>
blocks.map((block) => ({
): Block[] => {
const additionalElement: FEElement[] = [];
if (options.audioArticleImage) {
additionalElement.push(options.audioArticleImage);
}
return blocks.map((block) => ({
...block,
elements: enhanceElements(format, block.id, options)(block.elements),
elements: enhanceElements(
format,
block.id,
options,
)([...block.elements, ...additionalElement]),
}));
};
1 change: 0 additions & 1 deletion dotcom-rendering/src/model/front-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3153,7 +3153,6 @@
"fields",
"index",
"mediaType",
"mimeType",
"url"
]
},
Expand Down
1 change: 0 additions & 1 deletion dotcom-rendering/src/model/tag-page-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,6 @@
"fields",
"index",
"mediaType",
"mimeType",
"url"
]
},
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/types/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const enhanceArticleType = (
promotedNewsletter: data.promotedNewsletter,
imagesForLightbox,
hasAffiliateLinksDisclaimer: !!data.affiliateLinksDisclaimer,
audioArticleImage: data.audioArticleImage,
});

const mainMediaElements = enhanceMainMedia(
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ export interface Image {
caption?: string;
};
mediaType: string;
mimeType: string;
mimeType?: string;
url: string;
}

Expand Down
8 changes: 7 additions & 1 deletion dotcom-rendering/src/types/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import type { EditionId } from '../lib/edition';
import type { FEArticleBadgeType } from './badge';
import type { CommercialProperties } from './commercial';
import type { ConfigType, ServerSideTests } from './config';
import type { FEElement, Newsletter, StarRating } from './content';
import type {
FEElement,
ImageBlockElement,
Newsletter,
StarRating,
} from './content';
import type { FooterType } from './footer';
import type { FEOnwards } from './onwards';
import type { MatchType } from './sport';
Expand Down Expand Up @@ -85,6 +90,7 @@ export interface FEArticleType {
isCommentable: boolean;
commercialProperties: CommercialProperties;
starRating?: StarRating;
audioArticleImage?: ImageBlockElement;
trailText: string;
badge?: FEArticleBadgeType;

Expand Down

0 comments on commit 7bfc4ed

Please sign in to comment.