Skip to content

Commit db59df1

Browse files
authored
Merge pull request #26753 from guardian/sa-disclaimer-again
Lift affiliate links disclaimer out of page elements (again)
2 parents f2e627d + 1d4754a commit db59df1

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

common/app/model/dotcomrendering/DotcomRenderingDataModel.scala

+19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import navigation._
3131
import play.api.libs.json._
3232
import play.api.mvc.RequestHeader
3333
import services.NewsletterData
34+
import views.html.fragments.affiliateLinksDisclaimer
3435
import views.support.{CamelCase, ContentLayout, JavaScriptPage}
3536
// -----------------------------------------------------------------
3637
// DCR DataModel
@@ -41,6 +42,7 @@ case class DotcomRenderingDataModel(
4142
headline: String,
4243
standfirst: String,
4344
webTitle: String,
45+
affiliateLinksDisclaimer: Option[String],
4446
mainMediaElements: List[PageElement],
4547
main: String,
4648
availableTopics: Option[Seq[Topic]],
@@ -122,6 +124,7 @@ object DotcomRenderingDataModel {
122124
"headline" -> model.headline,
123125
"standfirst" -> model.standfirst,
124126
"webTitle" -> model.webTitle,
127+
"affiliateLinksDisclaimer" -> model.affiliateLinksDisclaimer,
125128
"mainMediaElements" -> model.mainMediaElements,
126129
"main" -> model.main,
127130
"filterKeyEvents" -> model.filterKeyEvents,
@@ -452,7 +455,14 @@ object DotcomRenderingDataModel {
452455
twitterHandle = content.tags.contributors.headOption.flatMap(_.properties.twitterHandle),
453456
)
454457

458+
def hasAffiliateLinks(
459+
blocks: Seq[APIBlock],
460+
): Boolean = {
461+
blocks.exists(block => DotcomRenderingUtils.stringContainsAffiliateableLinks(block.bodyHtml))
462+
}
463+
455464
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)
465+
val shouldAddDisclaimer = hasAffiliateLinks(bodyBlocks)
456466

457467
val contentDateTimes: ArticleDateTimes = ArticleDateTimes(
458468
webPublicationDate = content.trail.webPublicationDate,
@@ -545,7 +555,16 @@ object DotcomRenderingDataModel {
545555

546556
val selectedTopics = topicResult.map(topic => Seq(Topic(topic.`type`, topic.name)))
547557

558+
def getAffiliateLinksDisclaimer(shouldAddAffiliateLinks: Boolean, shouldAddDisclaimer: Boolean) = {
559+
if (shouldAddAffiliateLinks && shouldAddDisclaimer) {
560+
Some(affiliateLinksDisclaimer("article").body)
561+
} else {
562+
None
563+
}
564+
}
565+
548566
DotcomRenderingDataModel(
567+
affiliateLinksDisclaimer = getAffiliateLinksDisclaimer(shouldAddAffiliateLinks, shouldAddDisclaimer),
549568
author = author,
550569
badge = Badges.badgeFor(content).map(badge => DCRBadge(badge.seriesTag, badge.imageUrl)),
551570
beaconURL = Configuration.debug.beaconUrl,

common/app/model/dotcomrendering/DotcomRenderingUtils.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ object DotcomRenderingUtils {
188188
elem.`type` match {
189189
case Text =>
190190
val textString = elem.textTypeData.toList.mkString("\n") // just concat all the elems here for this test
191-
AffiliateLinksCleaner.stringContainsAffiliateableLinks(textString)
191+
stringContainsAffiliateableLinks(textString)
192192
case _ => false
193193
},
194194
)
@@ -201,6 +201,10 @@ object DotcomRenderingUtils {
201201
} else elems
202202
}
203203

204+
def stringContainsAffiliateableLinks(textString: String): Boolean = {
205+
AffiliateLinksCleaner.stringContainsAffiliateableLinks(textString)
206+
}
207+
204208
def blockElementsToPageElements(
205209
capiElems: Seq[ClientBlockElement],
206210
request: RequestHeader,

common/app/views/fragments/affiliateLinksDisclaimer.scala.html

+20-11
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33

44
@articleDisclaimer() = {
5-
<p><em><sup>
6-
This article contains affiliate links, which means we may earn a small commission if a reader clicks through and
7-
makes a purchase. All our journalism is independent and is in no way influenced by any advertiser or commercial initiative.
8-
By clicking on an affiliate link, you accept that third-party cookies will be set.
9-
<a href="https://www.theguardian.com/info/2017/nov/01/reader-information-on-affiliate-links" data-link-name="in body link" class="u-underline">More information</a>.
10-
</sup></em></p>
5+
<p><sup>
6+
The Guardian’s product and service reviews are independent and are
7+
in no way influenced by any advertiser or commercial initiative. We
8+
will earn a commission from the retailer if you buy something
9+
through an affiliate link.
10+
<a
11+
href="https://www.theguardian.com/info/2017/nov/01/reader-information-on-affiliate-links"
12+
data-link-name="in body link"
13+
class="u-underline"
14+
>Learn more</a
15+
>.
16+
</sup></p>
1117
}
1218

1319
@galleryDisclaimer() = {
14-
<br><em>This article contains affiliate links, which means we may earn a small commission if a reader clicks through and
15-
makes a purchase. All our journalism is independent and is in no way influenced by any advertiser or commercial initiative.
16-
By clicking on an affiliate link, you accept that third-party cookies will be set.
17-
<a href="https://www.theguardian.com/info/2017/nov/01/reader-information-on-affiliate-links">More information</a>.
18-
</em>
20+
<br>
21+
The Guardian’s product and service reviews are independent and are in no
22+
way influenced by any advertiser or commercial initiative. We will earn a
23+
commission from the retailer if you buy something through an affiliate link.
24+
<a
25+
href="https://www.theguardian.com/info/2017/nov/01/reader-information-on-affiliate-links"
26+
>Learn more</a
27+
>.
1928
}
2029

2130
@{contentType match {

common/app/views/support/HtmlCleaner.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,9 @@ object AffiliateLinksCleaner {
916916
contentType: String,
917917
skimlinksId: String,
918918
): Document = {
919-
920919
val linksToReplace: mutable.Seq[Element] = getAffiliateableLinks(html)
921920
linksToReplace.foreach { el => el.attr("href", linkToSkimLink(el.attr("href"), pageUrl, skimlinksId)) }
922-
923-
// respect appendDisclaimer, or if it's not set then always add the disclaimer if affilate links have been added
921+
// respect appendDisclaimer (for Galleries), or if it's not set then always add the disclaimer if affilate links have been added
924922
val shouldAppendDisclaimer = appendDisclaimer.getOrElse(linksToReplace.nonEmpty)
925923
if (shouldAppendDisclaimer) insertAffiliateDisclaimer(html, contentType)
926924
else html

0 commit comments

Comments
 (0)