Skip to content

Commit 1018711

Browse files
committed
add a separate gallery caption for dcr txt cleaning
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.
1 parent 4f80533 commit 1018711

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

common/app/model/dotcomrendering/DotcomBlocksRenderingDataModel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object DotcomBlocksRenderingDataModel {
6969
bodyBlocks: Seq[APIBlock],
7070
): DotcomBlocksRenderingDataModel = {
7171
val content = page.item
72-
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content) // TODO:
72+
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)
7373
val contentDateTimes = DotcomRenderingUtils.contentDateTimes(content)
7474

7575
val edition = Edition(request)

common/app/model/dotcomrendering/DotcomRenderingDataModel.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ object DotcomRenderingDataModel {
456456
): DotcomRenderingDataModel = {
457457

458458
val edition = Edition.edition(request)
459-
val content: ContentType = page.item
459+
val content = page.item
460460
val isImmersive = content.metadata.format.exists(_.display == ImmersiveDisplay)
461461
val isPaidContent = content.metadata.designType.contains(AdvertisementFeature)
462462

@@ -472,7 +472,6 @@ object DotcomRenderingDataModel {
472472
): Boolean = {
473473
content match {
474474
case gallery: Gallery => gallery.lightbox.containsAffiliateableLinks
475-
// TODO: I think the below could be used for galleries too, because the bodyHtml includes all the caption texts as well
476475
case _ => blocks.exists(block => DotcomRenderingUtils.stringContainsAffiliateableLinks(block.bodyHtml))
477476
}
478477
}

common/app/model/dotcomrendering/pageElements/TextCleaner.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import conf.Configuration.{affiliateLinks => affiliateLinksConfig}
55
import model.{Tag, Tags}
66
import org.jsoup.Jsoup
77
import org.jsoup.nodes.Document
8-
import views.support.{AffiliateLinksCleaner, GalleryCaptionCleaner, HtmlCleaner}
8+
import views.support.{AffiliateLinksCleaner, HtmlCleaner}
99

1010
import scala.jdk.CollectionConverters._
1111
import scala.util.matching.Regex
@@ -131,6 +131,27 @@ object TagLinker {
131131
}
132132
}
133133

134+
object GalleryCaptionCleaner extends HtmlCleaner {
135+
override def clean(galleryCaption: Document): Document = {
136+
// There is an inconsistent number of <br> tags in gallery captions.
137+
// To create some consistency, re will remove them all.
138+
galleryCaption.getElementsByTag("br").remove()
139+
140+
val firstStrong = Option(galleryCaption.getElementsByTag("strong").first())
141+
val captionTitle = galleryCaption.createElement("h2")
142+
val captionTitleText = firstStrong.map(_.html()).getOrElse("")
143+
144+
// <strong> is removed in place of having a <h2> element
145+
firstStrong.foreach(_.remove())
146+
147+
captionTitle.html(captionTitleText)
148+
149+
galleryCaption.body.prependChild(captionTitle)
150+
151+
galleryCaption
152+
}
153+
}
154+
134155
case class GalleryAffiliateLinksCleaner(
135156
pageUrl: String,
136157
shouldAddAffiliateLinks: Boolean,

0 commit comments

Comments
 (0)