Skip to content

Commit

Permalink
Add ad enhancer to enhanceBlocks fn
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie B <[email protected]>
  • Loading branch information
cemms1 and JamieB-gu committed Sep 11, 2023
1 parent 4a5593f commit dfc452d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ const adPlaceholder = (elements: FEElement[]): FEElement[] => {

return elementsWithAds.elements;
};

export const enhanceAdPlaceholders = (blocks: Block[]): Block[] =>
blocks.map((b) => ({
...b,
elements: adPlaceholder(b.elements),
}));
14 changes: 13 additions & 1 deletion dotcom-rendering/src/model/enhanceBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Newsletter } from '../types/content';
import { enhanceAdPlaceholders } from './adPlaceholder';
import { enhanceBlockquotes } from './enhance-blockquotes';
import { enhanceDividers } from './enhance-dividers';
import { enhanceDots } from './enhance-dots';
Expand Down Expand Up @@ -35,6 +36,16 @@ class BlockEnhancer {
return this;
}

enhanceAdPlaceholders() {
if (
!(this.format.design === 'LiveBlogDesign') &&
!(this.format.design === 'DeadBlogDesign')
) {
this.blocks = enhanceAdPlaceholders(this.blocks);
}
return this;
}

enhanceDividers() {
this.blocks = enhanceDividers(this.blocks);
return this;
Expand Down Expand Up @@ -106,5 +117,6 @@ export const enhanceBlocks = (
.enhanceNumberedLists()
.enhanceEmbeds()
.enhanceTweets()
.enhanceNewsletterSignup().blocks;
.enhanceNewsletterSignup()
.enhanceAdPlaceholders().blocks;
};

0 comments on commit dfc452d

Please sign in to comment.