sbt-typelevel-site

sbt-typelevel-site is an optional plugin for generating websites with mdoc and Laika and deploying to GitHub Pages from CI. You can add it to your build alongside either the sbt-typelevel or sbt-typelevel-ci-release plugin or also use it stand-alone.

Quick start

project/plugins.sbt

addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.7")

build.sbt

// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")

lazy val docs = project.in(file("site")).enablePlugins(TypelevelSitePlugin)

Place your .md files in the docs/ directory of your project. To preview locally, run docs/tlSitePreview. This will start a preview server at http://localhost:4242.

The site is generated using mdoc and Laika and published to the gh-pages branch on every push to the specified branch.

You will also need to configure your repository settings:

  1. Grant "Read and write" permissions to workflows. This enables them to push to the gh-pages branch. https://github.com/{user}/{repo}/settings/actions
  2. Set the GitHub pages source to the / (root) directory on the gh-pages branch. https://github.com/{user}/{repo}/settings/pages

Configuration

If you run the plugin with its defaults it will generate a site that will look like this documentation.

Below we'll describe how the default settings differ from Laika standalone as well as a few pointers for the most relevant customization options.

Site Default Settings

Whereas Laika standalone is a general purpose tool, this plugin's domain is project documentation which allows us to make a few additional assumptions and add useful defaults based on those.

On top of the defaults of Laika standalone, sbt-typelevel-site adds:

Additional Defaults for Typelevel Projects

If the generated documentation is for a Typelevel project (meaning its organization setting is org.typelevel), a set of additional defaults will be enabled on top of the generic defaults listed in the previous section:

If you are an affiliate project you can explicitly opt in to these settings:

tlSiteIsTypelevelProject := Some(TypelevelProject.Affiliate)

Finally, Typelevel projects can also opt out of these additional defaults:

tlSiteIsTypelevelProject := None

Customization

All customization options are based on Laika's configuration APIs for which we refer you to the comprehensive Laika manual and specifically the laikaTheme setting.

For all code examples in the Laika manual you need to replace Helium.defaults with tlSiteHelium.value unless you explicitly want to remove all additional defaults listed above. Everything else should be identical with using Laika standalone.

Some of the customization options which are most likely of interest in the context of project documentation:

For a complete list of customization options please see the full Laika documentation.

FAQ

How can I include my project version on the website?

sbt-typelevel-site automatically adds VERSION and SNAPSHOT_VERSION to the mdocVariables setting which can be used with variable injection.

For example, the sbt-typelevel VERSION is 0.6.7 and SNAPSHOT_VERSION is 0.7-9371b95-SNAPSHOT.

How can I publish "unidoc" API docs?

If you generate your API documentation with sbt-unidoc, you can use the TypelevelUnidocPlugin to publish a Scaladoc-only artifact to Sonatype/Maven alongside your library artifacts. This makes it possible to browse your unidocs at javadoc.io; for example, the sbt-typelevel API docs are published like this.

// Make sure to add to your root aggregate so it gets published!
lazy val unidocs = project
  .in(file("unidocs"))
  .enablePlugins(TypelevelUnidocPlugin) // also enables the ScalaUnidocPlugin
  .settings(
    name := "woozle-docs",
    ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(core.jvm, heffalump)
  )