Skip to content

Handle gallery affiliate links for dcar#28122

Merged
marjisound merged 3 commits intomainfrom
handle-gallery-affiliate-links-for-dcr
Aug 1, 2025
Merged

Handle gallery affiliate links for dcar#28122
marjisound merged 3 commits intomainfrom
handle-gallery-affiliate-links-for-dcr

Conversation

@marjisound
Copy link
Contributor

@marjisound marjisound commented Jul 25, 2025

What does this change?

Looking into the frontend version of the Gallery affiliate links, there are three main tasks that need to be completed for DCR migration.

  • Check if the captions contain affiliate links
  • Determine if affiliate links should be added, based on the following conditions: switch, showAffiliateLinks field, alwaysOffTags config & tags
  • If both of above conditions are true, affiliate links disclaimer is added in the header section of the page
  • Clean the captions by replacing the affiliate links with Simlinks

Note:

In galleryBody twirl template the GalleryCaptionCleaners is used for every image item to clean the caption. There are 2 cleaners involved:

  • GalleryCaptionCleaner which does the following:
    • removes <br> tags
    • retrieves the text content within the first <strong> and wraps it with <h2> element
    • removes the <strong> element
    • prepends the created h2 at the start of the caption
  • AffiliateLinksCleaner which does the following: checks if affiliate links should be added using the shouldAddAffiliateLinks function and then replaces affiliate links with Simlinks if necessary

Some updates:

I’ve re-created the two cleaners for the DCR model with adjustments:

  • GalleryCaptionCleaner: Removed the addition of the unnecessary gallery__caption__title class for DCR.
  • AffiliateLinksCleaner: The shouldAddAffiliateLinks check, which was previously applied to every image item, is no longer needed since the result of this check is already available in the DotcomRenderingDataModel. Instead the parapeter shouldAddAffiliateLinks is used in the new cleaner

Relevant DCAR PR: guardian/dotcom-rendering#14303

Fixes #12292

@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2025

@marjisound marjisound changed the title handle gallery affiliate links for dcar Handle gallery affiliate links for dcar Jul 29, 2025
The GalleryCaptionCleaner used by twirl template is adding a class that
is not needed for dcr, therefore, a separate cleaner is added
to handle the dcr case.
@marjisound marjisound force-pushed the handle-gallery-affiliate-links-for-dcr branch from 90ac628 to 1018711 Compare July 29, 2025 09:07
@marjisound marjisound marked this pull request as ready for review July 29, 2025 11:44
@marjisound marjisound requested a review from a team as a code owner July 29, 2025 11:44
@marjisound marjisound self-assigned this Jul 29, 2025
Copy link
Contributor

@emma-imber emma-imber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🚀 Just one small thing, but other than that, it looks fab from an affiliate links perspective

Copy link
Member

@arelra arelra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for separating out the DCR related gallery code from the existing Frontend logic. This will make the task of deleting Frontend code much easier

@marjisound marjisound merged commit 6010111 into main Aug 1, 2025
9 checks passed
@marjisound marjisound deleted the handle-gallery-affiliate-links-for-dcr branch August 1, 2025 08:01
@prout-bot
Copy link

Seen on ADMIN-PROD (merged by @marjisound 9 minutes and 57 seconds ago)

@prout-bot
Copy link

Seen on FRONTS-PROD (merged by @marjisound 12 minutes and 11 seconds ago)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Affiliate Links On Galleries

4 participants