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 the API base URI to the Laika config #225

Open
wants to merge 2 commits into
base: series/0.4
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import laika.helium.config.Favicon
import laika.helium.config.HeliumIcon
import laika.helium.config.IconLink
import laika.helium.config.ImageLink
import laika.rewrite.link.ApiLinks
import laika.rewrite.link.LinkConfig
import laika.sbt.LaikaPlugin
import laika.theme.ThemeProvider
import mdoc.MdocPlugin
Expand Down Expand Up @@ -105,6 +107,12 @@ object TypelevelSitePlugin extends AutoPlugin {
.value: @nowarn("cat=other-pure-statement"),
tlSitePreview := previewTask.value,
Laika / sourceDirectories := Seq(mdocOut.value),
laikaConfig := {
val currentConfig = laikaConfig.value
tlSiteApiUrl.value.fold(currentConfig) { apiUrl =>
currentConfig.withConfigValue(LinkConfig(apiLinks = Seq(ApiLinks(apiUrl.toString))))
Copy link
Member

Choose a reason for hiding this comment

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

Following on the additivity issue, .withConfigValue is definitely additive. But I assume that this will override any previously set LinkConfig and esp. all apiLinks previously set?

Copy link
Member Author

@DavidGregory084 DavidGregory084 Mar 24, 2022

Choose a reason for hiding this comment

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

I guess only way is to test it!

scala> import laika.sbt._
import laika.sbt._

scala> import laika.rewrite.link._
import laika.rewrite.link._

scala> val conf = LaikaConfig.defaults
conf: laika.sbt.LaikaConfig = LaikaConfig(UTF-8,<function1>,laika.config.ConfigBuilder@302e25d3,laika.ast.MessageFilter$$anon$1@78ea076,None,laika.ast.MessageFilter$$anon$1@56276b5d)

scala> val confWithLinks = conf.withConfigValue(LinkConfig(apiLinks = List(ApiLinks(baseUri = "https://www.javadoc.io/doc/com.github.cb372/scalacache-unidocs_2.13/0.28.0/"))))
confWithLinks: laika.sbt.LaikaConfig = LaikaConfig(UTF-8,<function1>,laika.config.ConfigBuilder@623f79d4,laika.ast.MessageFilter$$anon$1@78ea076,None,laika.ast.MessageFilter$$anon$1@56276b5d)
                                                                                                                                                                                                           
scala> val confWithMoreLinks = confWithLinks.withConfigValue(LinkConfig(apiLinks = List(ApiLinks(baseUri = "https://www.javadoc.io/doc/org.typelevel/sbt-typelevel-docs_2.12/latest/", "org.typelevel.sbt"))))
confWithMoreLinks: laika.sbt.LaikaConfig = LaikaConfig(UTF-8,<function1>,laika.config.ConfigBuilder@1698fd02,laika.ast.MessageFilter$$anon$1@78ea076,None,laika.ast.MessageFilter$$anon$1@56276b5d)

scala> confWithLinks.configBuilder.build.get[LinkConfig]("laika.links")
res0: laika.config.Config.ConfigResult[laika.rewrite.link.LinkConfig] = Right(LinkConfig(List(),List(),List(ApiLinks(https://www.javadoc.io/doc/com.github.cb372/scalacache-unidocs_2.13/0.28.0/,*,index.html)),List()))

scala> confWithMoreLinks.configBuilder.build.get[LinkConfig]("laika.links")
res1: laika.config.Config.ConfigResult[laika.rewrite.link.LinkConfig] = Right(LinkConfig(List(),List(),List(ApiLinks(https://www.javadoc.io/doc/org.typelevel/sbt-typelevel-docs_2.12/latest/,org.typelevel.sbt,index.html)),List()))

scala>

It looks like yes, latest ApiLinks wins 😬

}
},
laikaTheme := tlSiteHeliumConfig.value.build.extend(tlSiteHeliumExtensions.value),
mdocVariables := {
mdocVariables.value ++
Expand Down