Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Thumbnail image to DCR model for Audio Articles #27487

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import conf.Configuration
import crosswords.CrosswordPageWithContent
import experiments.ActiveExperiments
import model.dotcomrendering.DotcomRenderingUtils._
import model.dotcomrendering.pageElements.{PageElement, TextCleaner}
import model.dotcomrendering.pageElements.{ImageBlockElement, PageElement, Role, TextCleaner}
import model.liveblog.BlockAttributes
import model.{
ArticleDateTimes,
Badges,
CanonicalLiveBlog,
ContentFormat,
ContentPage,
CrosswordData,
DotcomContentType,
GUDateTimeFormatNew,
GalleryPage,
ImageContentPage,
Expand Down Expand Up @@ -87,6 +89,7 @@ case class DotcomRenderingDataModel(
commercialProperties: Map[String, EditionCommercialProperties],
pageType: PageType,
starRating: Option[Int],
audioArticleImage: Option[ImageBlockElement],
trailText: String,
nav: Nav,
showBottomSocialButtons: Boolean,
Expand Down Expand Up @@ -164,6 +167,7 @@ object DotcomRenderingDataModel {
"commercialProperties" -> model.commercialProperties,
"pageType" -> model.pageType,
"starRating" -> model.starRating,
"audioArticleImage" -> model.audioArticleImage,
"trailText" -> model.trailText,
"nav" -> model.nav,
"showBottomSocialButtons" -> model.showBottomSocialButtons,
Expand Down Expand Up @@ -500,6 +504,33 @@ object DotcomRenderingDataModel {

val dcrTags = content.tags.tags.map(Tag.apply)

val audioImageBlock: Option[ImageBlockElement] =
if (page.metadata.contentType.contains(DotcomContentType.Audio)) {
for {
thumbnail <- page.item.elements.thumbnail
} yield {
val imageData = thumbnail.images.allImages.headOption
.map { d =>
Map(
"copyright" -> "",
"alt" -> d.altText.getOrElse(""),
"caption" -> d.caption.getOrElse(""),
"credit" -> d.credit.getOrElse(""),
)
}
.getOrElse(Map.empty)
ImageBlockElement(
thumbnail.images,
imageData,
Some(true),
Role(Some("inline")),
Seq.empty,
)
}
} else {
None
}

def toDCRBlock(isMainBlock: Boolean = false) = { block: APIBlock =>
Block(
block = block,
Expand Down Expand Up @@ -565,6 +596,7 @@ object DotcomRenderingDataModel {

DotcomRenderingDataModel(
affiliateLinksDisclaimer = addAffiliateLinksDisclaimerDCR(shouldAddAffiliateLinks, shouldAddDisclaimer),
audioArticleImage = audioImageBlock,
author = author,
badge = Badges.badgeFor(content).map(badge => DCRBadge(badge.seriesTag, badge.imageUrl)),
beaconURL = Configuration.debug.beaconUrl,
Expand Down
Loading