Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Instead of using the super-plugins, for finer-grained control you can always add
- `TypelevelSitePlugin`: Sets up an [mdoc](https://scalameta.org/mdoc/)/[Laika](https://planet42.github.io/Laika/)-generated website, automatically published to GitHub pages in CI.
- `tlSitePublishBranch` (setting): The branch to publish the site from on every push. Set this to `None` if you only want to update the site on tag releases. (default: `main`)
- `tlSitePublishTags` (setting): Defines whether the site should be published on tag releases. Note on setting this to `true` requires the `tlSitePublishBranch` setting to be set to `None`. (default: `false`)
- `tlSiteApiLinks` (setting): Map of package prefixes to API documentation sites for use with Laika API links. (default: * -> `tlSiteApiUrl`, if available)
- `tlSiteApiUrl` (setting): URL to the API docs. (default: `None`)
- `tlSiteHeliumConfig` (setting): the Laika Helium config. (default: how the sbt-typelevel site looks)

Expand Down
11 changes: 11 additions & 0 deletions site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala
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 All @@ -45,6 +47,8 @@ object TypelevelSitePlugin extends AutoPlugin {
lazy val tlSiteHeliumConfig = settingKey[Helium]("The Typelevel Helium configuration")
lazy val tlSiteHeliumExtensions =
settingKey[ThemeProvider]("The Typelevel Helium extensions")
lazy val tlSiteApiLinks =
settingKey[Map[String, URL]]("URLs to API doc roots, by package prefix")
lazy val tlSiteApiUrl = settingKey[Option[URL]]("URL to the API docs")
lazy val tlSiteApiModule =
settingKey[Option[ModuleID]]("The module that publishes API docs")
Expand Down Expand Up @@ -85,6 +89,7 @@ object TypelevelSitePlugin extends AutoPlugin {
override def buildSettings = Seq(
tlSitePublishBranch := Some("main"),
tlSitePublishTags := tlSitePublishBranch.value.isEmpty,
tlSiteApiLinks := tlSiteApiUrl.value.map("*" -> _).toMap,
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately the tlSiteApiUrl is not the "base" URL for the API. See (1) in #225 (comment).

So maybe we need to add a tlSiteApiBaseUrl or something ...

Copy link
Member

Choose a reason for hiding this comment

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

I also wonder if it would be helpful to populate this with some useful defaults. Like for Cats and Cats Effect and stuff, since I assume downstream documentation will want to reference it fairly frequently.

Copy link
Author

Choose a reason for hiding this comment

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

That's too bad, tlSiteApiUrl worked fine for Cats. Is there a reasonable situation where stripping off everything after the last / wouldn't work? Or only defaulting to tlSiteApiUrl if it ends in / ?

If tlSiteApiBaseUrl would only be used for tlSiteApiLinks, we may as well just have users populate tlSiteApiLinks themselves instead of adding yet another setting.

Is there a way to get those common library versions inside the plugin? I wouldn't want to embed specific versions in the defaults.

Copy link
Member

@armanbilge armanbilge Jan 31, 2023

Choose a reason for hiding this comment

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

Is there a reasonable situation where stripping off everything after the last / wouldn't work?

Yeah, so for example http4s-dom sets its tlSiteApiUrl to this, so it "zooms" to the right package.

https://www.javadoc.io/doc/org.http4s/http4s-dom_sjs1_2.13/0.2.6/org/http4s/dom/index.html

So I don't think it would work there.


tlSiteApiBaseUrl can be used to make tlSiteApiUrl and in many cases it will be auto-populated by the unidocs plugin. tlSiteApiUrl wasn't the right primitive.


Is there a way to get those common library versions inside the plugin? I wouldn't want to embed specific versions in the defaults.

Ugh, good point, I forgot about this trickyness. Blah. We could try scouring the classpath for this information but it's a bit hacky. I have to think about this.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to get those common library versions inside the plugin?

Actually, we should try and use the same mechanism that sbt uses for API mappings. These are read out of the dependencies. Essentially Laika is replicating this same feature, we just need to glue them together. This might even be upstreamable into sbt-Laika.

Copy link
Member

Choose a reason for hiding this comment

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

So have we circled back to providing tlSiteApiBaseUrl then?

I think you also have to provide your package as well? Funny enough we might have an existing setting for that.

But I want to think about this more.

Copy link
Author

@reardonj reardonj Jan 31, 2023

Choose a reason for hiding this comment

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

…on the other hand, given the dream is to obsolete most of that config, and it's a one time bit of work on the project being documented, maybe it's best not to add more machinery. here.

Copy link
Author

Choose a reason for hiding this comment

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

I think you also have to provide your package as well? Funny enough we might have an existing setting for that.

You can provide "*" as an explicit fallback (which is what the case class defaults to) and it handles that specially as a fallback if there is no match. So you don't need to provide your own prefix.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but what happens if my project is org.http4s.dom and sbt-typelevel had pre-loaded org.http4s API docs for me. It just doesn't work in general.

Copy link
Author

Choose a reason for hiding this comment

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

uhh; right

tlSiteApiUrl := None,
tlSiteApiPackage := None,
tlSiteRelatedProjects := Seq(TypelevelProject.Cats),
Expand All @@ -106,6 +111,12 @@ object TypelevelSitePlugin extends AutoPlugin {
.value: @nowarn("cat=other-pure-statement"),
tlSitePreview := previewTask.value,
Laika / sourceDirectories := Seq(mdocOut.value),
laikaConfig := laikaConfig
.value
.withConfigValue(LinkConfig(apiLinks = tlSiteApiLinks.value.toList.map {
case (packagePrefix, baseUri) =>
ApiLinks(packagePrefix = packagePrefix, baseUri = baseUri.toString)
})),
Comment on lines +116 to +119
Copy link
Member

Choose a reason for hiding this comment

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

Does the order here matter? e.g. what happens if the cats prefix comes before the cats.effect prefix?

Copy link
Author

Choose a reason for hiding this comment

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

Order doesn't matter, Laika uses longest prefix match.

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