-
Notifications
You must be signed in to change notification settings - Fork 50
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -49,6 +51,9 @@ object TypelevelSitePlugin extends AutoPlugin { | |
settingKey[Option[ModuleID]]("The module that publishes API docs") | ||
lazy val tlSiteApiPackage = settingKey[Option[String]]( | ||
"The top-level package for your API docs (e.g. org.typlevel.sbt)") | ||
lazy val tlSiteApiIndexUrl = | ||
settingKey[Option[URL]]( | ||
"The URL of the index page for the top-level package of your API docs") | ||
lazy val tlSiteRelatedProjects = | ||
settingKey[Seq[(String, URL)]]("A list of related projects (default: cats)") | ||
|
||
|
@@ -85,6 +90,7 @@ object TypelevelSitePlugin extends AutoPlugin { | |
tlSitePublishBranch := Some("main"), | ||
tlSitePublishTags := tlSitePublishBranch.value.isEmpty, | ||
tlSiteApiUrl := None, | ||
tlSiteApiIndexUrl := None, | ||
tlSiteApiPackage := None, | ||
tlSiteRelatedProjects := Seq(TypelevelProject.Cats), | ||
tlSiteKeepFiles := true, | ||
|
@@ -105,6 +111,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)))) | ||
} | ||
}, | ||
laikaTheme := tlSiteHeliumConfig.value.build.extend(tlSiteHeliumExtensions.value), | ||
mdocVariables := { | ||
mdocVariables.value ++ | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Right. I think instead we should add a new setting |
||
}, | ||
tlSiteHeliumExtensions := TypelevelHeliumExtensions( | ||
licenses.value.headOption, | ||
|
@@ -132,12 +144,15 @@ object TypelevelSitePlugin extends AutoPlugin { | |
val o = moduleId.organization | ||
val n = cross(moduleId.name) | ||
val v = version | ||
val p = tlSiteApiPackage.value.fold("")(_.replace('.', '/') + "/index.html") | ||
url(s"https://www.javadoc.io/doc/$o/$n/$v/$p") | ||
url(s"https://www.javadoc.io/doc/$o/$n/$v/") | ||
} | ||
|
||
tlSiteApiUrl.value.orElse(javadocioUrl) | ||
}, | ||
tlSiteApiIndexUrl := tlSiteApiUrl.value.map { apiURL => | ||
val apiIndex = tlSiteApiPackage.value.fold("")(_.replace('.', '/') + "/index.html") | ||
apiURL.toURI.resolve(apiIndex).toURL | ||
}, | ||
tlSiteHeliumConfig := { | ||
Helium | ||
.defaults | ||
|
@@ -170,9 +185,9 @@ object TypelevelSitePlugin extends AutoPlugin { | |
"https://typelevel.org", | ||
Image.external(s"https://typelevel.org/img/logo.svg") | ||
), | ||
navLinks = tlSiteApiUrl.value.toList.map { url => | ||
navLinks = tlSiteApiIndexUrl.value.toList.map { apiIndex => | ||
IconLink.external( | ||
url.toString, | ||
apiIndex.toString, | ||
HeliumIcon.api, | ||
options = Styles("svg-link") | ||
) | ||
|
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 setLinkConfig
and esp. allapiLinks
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!
It looks like yes, latest
ApiLinks
wins 😬