-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: series/0.4
Are you sure you want to change the base?
Add the API base URI to the Laika config #225
Conversation
Aha, very nice! I was recently experimenting with this feature in http4s-dom. I really want to do something like this too. There's a couple bits of trickyness:
WDYT? |
Hmm yes I see what you mean; I was testing this with scalacache but I neglected to set the
Yeah it seems the Laika config is a little tricky to work with in general, although I think that |
laikaConfig := { | ||
val currentConfig = laikaConfig.value | ||
tlSiteApiUrl.value.fold(currentConfig) { apiUrl => | ||
currentConfig.withConfigValue(LinkConfig(apiLinks = Seq(ApiLinks(apiUrl.toString)))) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😬
Yeah, although it's less about the usage of
Yeppp. For example, right now I don't think it's possible to modify the config to replace/remove the Typelevel logo and social links at the top without losing the API and github links as well. This is unfortunate for the http4s plugin which has to replicate this functionality and for anyone outside Typelevel that wants to enjoy the goodies in this plugin. So, our recourse is to expose all these things in sbt settings, as I'm tempted to here. Then we can auto-populate it with useful stuff (like the projects own API docs) while letting downstreams add whatever else they might need. Edit: I guess the upstream fix is for Laika to expose the current config in the builder, if possible. But working with nested case classes starts needing lenses and the usability starts to get tricky. |
… base package of the project
@@ -113,7 +125,7 @@ object TypelevelSitePlugin extends AutoPlugin { | |||
"PRERELEASE_VERSION" -> currentPreRelease.value.getOrElse(version.value), | |||
"SNAPSHOT_VERSION" -> version.value | |||
) ++ | |||
tlSiteApiUrl.value.map("API_URL" -> _.toString).toMap | |||
tlSiteApiIndexUrl.value.map("API_URL" -> _.toString).toMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried adding a new setting to capture the distinction between the index page + the API base URL, but I don't love that these names are now out of sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I think instead we should add a new setting tlSiteApiLinks
that's maybe like Map[String -> url]
package name to API docs url. Then we can make a best effort to populate this.
This enables the API Documentation Linking feature of Laika to work if API doc base URL is declared in the build config.