Skip to content

Commit 186ee8b

Browse files
committed
prevent placeholder inclusion if article shouldHideAds is true
1 parent 18e4b60 commit 186ee8b

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ const debounceUpdateAds = libDebounce(updateAds, 100, { leading: true });
105105
export const AdPortals = ({
106106
rightAlignFrom = 'desktop',
107107
}: {
108-
/** In most cases, we want to try to display ads in the right column from desktop upwards.
109-
* For blogs, we want right aligned from wide upwards.
110-
*/
108+
// In most cases, we want to try to display ads in the right column from desktop upwards.
109+
// For blogs, we want right aligned from wide upwards.
111110
rightAlignFrom?: Breakpoint;
112111
}) => {
113112
// Server-rendered placeholder elements for inline ad slots to be inserted into (below desktop breakpoint)

dotcom-rendering/src/components/LiveBlock.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Props = {
2525
isPinnedPost: boolean;
2626
pinnedPostId?: string;
2727
editionId: EditionId;
28+
shouldHideAds?: boolean;
2829
};
2930

3031
export const LiveBlock = ({
@@ -42,6 +43,7 @@ export const LiveBlock = ({
4243
isPinnedPost,
4344
pinnedPostId,
4445
editionId,
46+
shouldHideAds,
4547
}: Props) => {
4648
if (block.elements.length === 0) return null;
4749

@@ -86,6 +88,7 @@ export const LiveBlock = ({
8688
switches={switches}
8789
isPinnedPost={isPinnedPost}
8890
editionId={editionId}
91+
shouldHideAds={shouldHideAds}
8992
/>
9093
))}
9194
<footer

dotcom-rendering/src/components/LiveBlogBlocksAndAdverts.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Props = {
2323
isAdFreeUser: boolean;
2424
isSensitive: boolean;
2525
isLiveUpdate?: boolean;
26+
shouldHideAds?: boolean;
2627
};
2728
/**
2829
* On liveblogs we insert two sets of ad slots into the page: one set for small
@@ -46,6 +47,7 @@ export const LiveBlogBlocksAndAdverts = ({
4647
isSensitive,
4748
isLiveUpdate,
4849
editionId,
50+
shouldHideAds,
4951
}: Props) => {
5052
const { renderingTarget } = useConfig();
5153
const isWeb = renderingTarget === 'Web';
@@ -72,7 +74,7 @@ export const LiveBlogBlocksAndAdverts = ({
7274
);
7375
};
7476

75-
if (isAdFreeUser) {
77+
if (isAdFreeUser || shouldHideAds) {
7678
return (
7779
<>
7880
{blocks.map((block) => (

dotcom-rendering/src/layouts/FullPageInteractiveLayout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type RendererProps = {
6565
abTests: ServerSideTests;
6666
switches: Switches;
6767
editionId: EditionId;
68+
shouldHideAds: boolean;
6869
};
6970

7071
const Renderer = ({
@@ -79,6 +80,7 @@ const Renderer = ({
7980
abTests,
8081
switches,
8182
editionId,
83+
shouldHideAds,
8284
}: RendererProps) => {
8385
// const cleanedElements = elements.map(element =>
8486
// 'html' in element ? { ...element, html: clean(element.html) } : element,
@@ -100,6 +102,7 @@ const Renderer = ({
100102
abTests,
101103
switches,
102104
editionId,
105+
shouldHideAds,
103106
});
104107

105108
switch (element._type) {
@@ -305,6 +308,7 @@ export const FullPageInteractiveLayout = (props: WebProps | AppsProps) => {
305308
isAdFreeUser={article.isAdFreeUser}
306309
isSensitive={article.config.isSensitive}
307310
editionId={article.editionId}
311+
shouldHideAds={article.shouldHideAds}
308312
/>
309313
</article>
310314
</Section>

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Props = {
9393
totalElements?: number;
9494
isListElement?: boolean;
9595
isSectionedMiniProfilesArticle?: boolean;
96+
shouldHideAds?: boolean;
9697
};
9798

9899
// updateRole modifies the role of an element in a way appropriate for most
@@ -153,6 +154,7 @@ export const renderElement = ({
153154
totalElements = 0,
154155
isListElement = false,
155156
isSectionedMiniProfilesArticle = false,
157+
shouldHideAds,
156158
}: Props) => {
157159
const isBlog =
158160
format.design === ArticleDesign.LiveBlog ||
@@ -531,7 +533,7 @@ export const renderElement = ({
531533
if (isListElement || isTimeline) return null;
532534
return <EmailSignUpWrapper {...emailSignUpProps} />;
533535
case 'model.dotcomrendering.pageElements.AdPlaceholderBlockElement':
534-
return <AdPlaceholder />;
536+
return !shouldHideAds && <AdPlaceholder />;
535537
case 'model.dotcomrendering.pageElements.NumberedTitleBlockElement':
536538
return (
537539
<NumberedTitleBlockComponent
@@ -713,6 +715,7 @@ export const renderElement = ({
713715
host,
714716
isPinnedPost,
715717
starRating,
718+
shouldHideAds,
716719
})}
717720
format={format}
718721
/>
@@ -925,6 +928,7 @@ export const RenderArticleElement = ({
925928
totalElements,
926929
isListElement,
927930
isSectionedMiniProfilesArticle,
931+
shouldHideAds,
928932
}: Props) => {
929933
const withUpdatedRole = updateRole(element, format);
930934

@@ -950,6 +954,7 @@ export const RenderArticleElement = ({
950954
totalElements,
951955
isListElement,
952956
isSectionedMiniProfilesArticle,
957+
shouldHideAds,
953958
});
954959

955960
const needsFigure = !bareElements.has(element._type);

0 commit comments

Comments
 (0)