Skip to content

Commit

Permalink
Merge branch 'main' into jlk/delete-old-api-code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeii authored Jan 30, 2025
2 parents e23bbda + 1ac9f20 commit dd35a9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
14 changes: 12 additions & 2 deletions common/app/common/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BadConfigurationException(msg: String) extends RuntimeException(msg)

object Environment extends GuLogging {

private[this] val installVars = {
private[this] val installVars: Map[String, String] = {
val source = new File("/etc/gu/install_vars") match {
case f if f.exists => IOUtils.toString(new FileInputStream(f), Charset.defaultCharset())
case _ => ""
Expand All @@ -34,7 +34,17 @@ object Environment extends GuLogging {

// Prefer env vars over install vars over default
private[this] def get(name: String, default: String): String = {
sys.env.get(name.toUpperCase).orElse(installVars.get(name)).getOrElse(default)
sys.env.get(name.toUpperCase) match {
case Some(env) =>
log.info(s"Environment lookup: resolved $name from environment variable")
env
case _ if installVars.contains(name) =>
log.info(s"Environment lookup: resolved $name from install_vars")
installVars(name)
case _ =>
log.info(s"Environment lookup: resolved $name from default value")
default
}
}

val stack = get("stack", "frontend")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object TextCleaner {
val links = AffiliateLinksCleaner.getAffiliateableLinks(doc)
links.foreach(el => {
val id = affiliateLinksConfig.skimlinksId
el.attr("href", AffiliateLinksCleaner.linkToSkimLink(el.attr("href"), pageUrl, id))
el.attr("href", AffiliateLinksCleaner.linkToSkimLink(el.attr("href"), pageUrl, id)).attr("rel", "sponsored")
})

if (links.nonEmpty) {
Expand Down
8 changes: 6 additions & 2 deletions common/app/views/support/HtmlCleaner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,18 @@ object AffiliateLinksCleaner {
skimlinksId: String,
): Document = {
val linksToReplace: mutable.Seq[Element] = getAffiliateableLinks(html)
linksToReplace.foreach { el => el.attr("href", linkToSkimLink(el.attr("href"), pageUrl, skimlinksId)) }
linksToReplace.foreach { el =>
el.attr("href", linkToSkimLink(el.attr("href"), pageUrl, skimlinksId)).attr("rel", "sponsored")
}
html
}

def replaceLinksInElement(html: String, pageUrl: String): TextBlockElement = {
val doc = Jsoup.parseBodyFragment(html)
val linksToReplace: mutable.Seq[Element] = getAffiliateableLinks(doc)
linksToReplace.foreach { el => el.attr("href", linkToSkimLink(el.attr("href"), pageUrl, skimlinksId)) }
linksToReplace.foreach { el =>
el.attr("href", linkToSkimLink(el.attr("href"), pageUrl, skimlinksId)).attr("rel", "sponsored")
}

if (linksToReplace.nonEmpty) {
TextBlockElement(doc.body().html())
Expand Down
1 change: 1 addition & 0 deletions dev-build/app/AppLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ trait AppComponents
wire[StocksDataLifecycle],
wire[NewsletterSignupLifecycle],
wire[MostViewedLifecycle],
wire[SkimLinksCacheLifeCycle],
)

override lazy val httpFilters = wire[DevFilters].filters
Expand Down

0 comments on commit dd35a9f

Please sign in to comment.