Skip to content

Commit f61abae

Browse files
committed
Insert merchandising slot and update css to have space on the sides in mobile plus refactoring
1 parent e07363c commit f61abae

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

dotcom-rendering/src/components/GalleryAdSlots.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const MobileAdSlot = ({
1818
);
1919
};
2020

21-
export const GalleryInlineAdSlot = ({
21+
export const GalleryDesktopAdSlot = ({
2222
renderAds,
2323
adSlotIndex,
2424
}: {

dotcom-rendering/src/layouts/GalleryLayout.tsx

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ArticleTitle } from '../components/ArticleTitle';
1515
import { Caption } from '../components/Caption';
1616
import { Footer } from '../components/Footer';
1717
import {
18-
GalleryInlineAdSlot,
18+
GalleryDesktopAdSlot,
1919
MobileAdSlot,
2020
} from '../components/GalleryAdSlots';
2121
import { GalleryImage } from '../components/GalleryImage';
@@ -27,13 +27,10 @@ import { Section } from '../components/Section';
2727
import { Standfirst } from '../components/Standfirst';
2828
import { SubMeta } from '../components/SubMeta';
2929
import { grid } from '../grid';
30-
import type { ArticleFormat } from '../lib/articleFormat';
30+
import { type ArticleFormat, ArticleSpecial } from '../lib/articleFormat';
3131
import { canRenderAds } from '../lib/canRenderAds';
3232
import { decideMainMediaCaption } from '../lib/decide-caption';
33-
import {
34-
getDesktopAdPositions,
35-
getMobileAdPositions,
36-
} from '../lib/getGalleryAdPositions';
33+
import { getAdPositions } from '../lib/getGalleryAdPositions';
3734
import type { NavType } from '../model/extract-nav';
3835
import { palette as themePalette } from '../palette';
3936
import type { Gallery } from '../types/article';
@@ -81,11 +78,8 @@ const galleryItemAdvertStyles = css`
8178
`;
8279

8380
const galleryInlineAdContainerStyles = css`
84-
${grid.column.all}
85-
86-
${from.tablet} {
87-
${grid.column.centre}
88-
}
81+
${grid.column.centre}
82+
z-index: 1;
8983
9084
${from.desktop} {
9185
padding-bottom: ${space[10]}px;
@@ -142,15 +136,11 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
142136
theme: gallery.theme,
143137
};
144138

145-
const renderAds = canRenderAds(frontendData);
139+
const isLabs = format.theme === ArticleSpecial.Labs;
146140

147-
const desktopAdPositions = renderAds
148-
? getDesktopAdPositions(gallery.images)
149-
: [];
141+
const renderAds = canRenderAds(frontendData);
150142

151-
const mobileAdPositions = renderAds
152-
? getMobileAdPositions(gallery.images)
153-
: [];
143+
const adPositions = renderAds ? getAdPositions(gallery.images) : [];
154144

155145
return (
156146
<>
@@ -277,12 +267,7 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
277267
</header>
278268
{gallery.images.map((element, idx) => {
279269
const index = idx + 1;
280-
const shouldShowDesktopAd =
281-
desktopAdPositions.includes(index);
282-
const shouldShowMobileAd =
283-
mobileAdPositions.includes(index);
284-
const shouldShowAnyAd =
285-
shouldShowDesktopAd || shouldShowMobileAd;
270+
const shouldShowAds = adPositions.includes(index);
286271

287272
return (
288273
<Fragment key={element.elementId}>
@@ -292,7 +277,7 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
292277
pageId={frontendData.pageId}
293278
webTitle={frontendData.webTitle}
294279
/>
295-
{isWeb && shouldShowAnyAd && (
280+
{isWeb && shouldShowAds && (
296281
<div
297282
className={[
298283
'gallery__item gallery__item--advert',
@@ -303,23 +288,19 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
303288
className="gallery__img-container"
304289
css={galleryInlineAdContainerStyles}
305290
>
306-
{shouldShowDesktopAd && (
307-
<GalleryInlineAdSlot
308-
renderAds={renderAds}
309-
adSlotIndex={desktopAdPositions.indexOf(
310-
index,
311-
)}
312-
/>
313-
)}
291+
<GalleryDesktopAdSlot
292+
renderAds={renderAds}
293+
adSlotIndex={adPositions.indexOf(
294+
index,
295+
)}
296+
/>
314297

315-
{shouldShowMobileAd && (
316-
<MobileAdSlot
317-
renderAds={renderAds}
318-
adSlotIndex={mobileAdPositions.indexOf(
319-
index,
320-
)}
321-
/>
322-
)}
298+
<MobileAdSlot
299+
renderAds={renderAds}
300+
adSlotIndex={adPositions.indexOf(
301+
index,
302+
)}
303+
/>
323304
</div>
324305
<div css={galleryBorder}></div>
325306
</div>
@@ -357,6 +338,18 @@ export const GalleryLayout = (props: WebProps | AppProps) => {
357338
/>
358339
</Section>
359340
)}
341+
{isWeb && renderAds && !isLabs && (
342+
<Section
343+
fullWidth={true}
344+
padSides={false}
345+
showTopBorder={false}
346+
showSideBorders={false}
347+
backgroundColour={themePalette('--ad-background')}
348+
element="aside"
349+
>
350+
<AdSlot position="merchandising" display={format.display} />
351+
</Section>
352+
)}
360353
{isWeb && (
361354
<Section
362355
fullWidth={true}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type { ImageBlockElement } from '../types/content';
22

3-
const getMobileAdPositions = (images: ImageBlockElement[]): number[] => {
3+
/**
4+
* @param images - An array of ImageBlockElement objects representing the images in the gallery.
5+
* @description This function calculates the positions in the gallery where ads should be placed.
6+
* The ad position will be the same for all breakpoints, after every 4 images will have an ad slot.
7+
* What make the difference between mobile and desktop slot ids are in GalleryAdSlots.tsx and AdSlot.web.tsx.
8+
* @returns An array of numbers representing the positions where ads should be placed.
9+
*/
10+
const getAdPositions = (images: ImageBlockElement[]): number[] => {
411
const adPositions = images
512
.map((image) => images.indexOf(image) + 1)
613
.filter((position) => position % 4 === 0);
714
return adPositions;
815
};
916

10-
const getDesktopAdPositions = (images: ImageBlockElement[]): number[] => {
11-
const adPositions = images
12-
.map((image) => images.indexOf(image) + 1)
13-
.filter((position) => position % 4 === 0);
14-
return adPositions;
15-
};
16-
17-
export { getDesktopAdPositions, getMobileAdPositions };
17+
export { getAdPositions };

0 commit comments

Comments
 (0)