Skip to content

Commit

Permalink
Merge pull request #143 from http4s/feature/http4s-helium-extensions
Browse files Browse the repository at this point in the history
Create http4s Laika/Helium theme
  • Loading branch information
armanbilge authored Mar 2, 2022
2 parents 9a170b9 + b9c898b commit 05988b0
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Triggers automatically. Use on all http4s modules.

### `Http4sOrgSitePlugin`

Must be manually triggered. Extends the `TypelevelSitePlugin` with the http4s.org theme. See the [sbt-typelevel-site docs](https://typelevel.org/sbt-typelevel/#how-do-i-publish-a-site-like-this-one) for usage.
Must be manually triggered. Extends the `TypelevelSitePlugin` with the http4s.org theme. See the [sbt-typelevel-site docs](https://typelevel.org/sbt-typelevel/site.html) for usage.
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ lazy val core = project
name := "sbt-http4s-org"
)

lazy val docs = project.in(file("site")).enablePlugins(Http4sOrgSitePlugin)
lazy val docs = project
.in(file("site"))
.enablePlugins(Http4sOrgSitePlugin)
.settings(
tlSiteRelatedProjects += ("sbt-typelevel" -> url("https://typelevel.org/sbt-typelevel/"))
)

ThisBuild / tlBaseVersion := "0.12"
ThisBuild / crossScalaVersions := Seq("2.12.15")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Laika 0.18.0 + Helium Theme" />
<meta name="generator" content="Laika 0.18.1 + Helium Theme" />
<title>${cursor.currentDocument.title}</title>
@:for(laika.site.metadata.authors)
<meta name="author" content="${_}"/>
Expand All @@ -13,7 +13,7 @@
<meta name="description" content="${_}"/>
@:@
@:for(helium.favIcons)
<link rel="icon" @:attribute(sizes, _.sizes) @:attribute(type, _.type) @:attribute(href, _.target)/>
<link rel="icon" @:attribute(sizes, _.sizes) @:attribute(type, _.type) href="@:path(_.target)"/>
@:@
@:for(helium.webFonts)
<link rel="stylesheet" href="${_}">
Expand All @@ -29,20 +29,21 @@

<header id="top-bar">

<!-- visibility trickery, for layout to match http4s.org -->
<div class="row" style="visibility:hidden">
<div class="row">
<a id="nav-icon">
@:icon(navigationMenu)
</a>
@:for(laika.versions)
<div id="version-menu-container">
<a id="version-menu-toggle" class="text-link drop-down-toggle" href="#">
Version 1.0
${helium.topBar.versionPrefix} ${_.currentVersion.displayValue}
</a>
<nav id="version-menu">
<ul id="version-list" class="nav-list">
</ul>
</nav>
</div>
@:@
</div>

${?helium.topBar.home}
Expand All @@ -63,13 +64,9 @@

<ul class="nav-list">
<li class="level1 nav-header">Related Projects</li>
<li class="level2"><a href="https://http4s.org/">http4s</a></li>
<li class="level2"><a href="https://github.com/http4s/blaze">blaze</a></li>
<li class="level2"><a href="https://jdk-http-client.http4s.org/">http4s-jdk-http-client</a></li>
<li class="level2"><a href="https://http4s.github.io/http4s-dom/">http4s-dom</a></li>
<li class="level2"><a href="https://github.com/http4s/rho">rho</a></li>
<li class="level2"><a href="https://github.com/http4s/sbt-http4s-org">sbt-http4s-org</a></li>
<li class="level2"><a href="https://github.com/typelevel/feral">feral</a></li>
@:for(typelevel.site.related)
<li class="level2"><a href="${_.url}">${_.name}</a></li>
@:@
</ul>
<!-- custom end -->

Expand All @@ -96,7 +93,7 @@
<!-- custom start - integrate footer, a feature not yet available in Helium -->
<hr style="margin-top: 30px"/>
<footer style="font-size: 90%; text-align: center">
http4s is a <a href="https://typelevel.org/">Typelevel</a> Project distributed under the <a href="https://github.com/http4s/http4s/LICENSE">Apache 2 License</a>.
http4s is a <a href="https://typelevel.org/">Typelevel</a> Project distributed under the <a href="https://github.com/http4s/http4s/blob/main/LICENSE">Apache 2 License</a>.
</footer>
<!-- custom end -->

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions core/src/main/resources/org/http4s/sbt/site/images/http4s-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 21 additions & 21 deletions core/src/main/scala/org/http4s/sbt/Http4sOrgSitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.http4s.sbt

import cats.effect.IO
import laika.ast.LengthUnit._
import laika.ast.Path.Root
import laika.ast._
Expand All @@ -25,7 +24,6 @@ import laika.helium.config.Favicon
import laika.helium.config.HeliumIcon
import laika.helium.config.IconLink
import laika.helium.config.ImageLink
import laika.rewrite.DefaultTemplatePath
import laika.sbt.LaikaPlugin
import laika.theme.config.Color
import org.typelevel.sbt._
Expand All @@ -36,27 +34,32 @@ object Http4sOrgSitePlugin extends AutoPlugin {

override def requires = TypelevelSitePlugin && LaikaPlugin

import TypelevelGitHubPlugin.autoImport._
import TypelevelSitePlugin.autoImport._
import LaikaPlugin.autoImport._

override def projectSettings: Seq[Setting[_]] = Seq(
laikaInputs ~= {
// Laika natively supports classpath resources but there's something fiddly with that in sbt
_.delegate
.addStream(
IO.blocking(getClass.getResourceAsStream("default.template.html")),
DefaultTemplatePath.forHTML
)
.addStream(
IO.blocking(getClass.getResourceAsStream("site/styles.css")),
Root / "site" / "styles.css"
)
tlSiteRelatedProjects := {
Seq(
"http4s" -> url("https://http4s.org/"),
"blaze" -> url("https://github.com/http4s/blaze"),
"http4s-jdk-http-client" -> url("https://jdk-http-client.http4s.org/"),
"http4s-dom" -> url("https://http4s.github.io/http4s-dom/"),
"rho" -> url("https://github.com/http4s/rho"),
"sbt-http4s-org" -> url("https://http4s.github.io/sbt-http4s-org/"),
"feral" -> url("https://github.com/typelevel/feral")
).filterNot { case (repo, _) =>
tlGitHubRepo.value.contains(repo) // omit ourselves!
}
},
laikaTheme ~= { _.extend(site.Http4sHeliumExtensions) },
tlSiteHeliumConfig := {
Helium.defaults.all
.metadata(
title = tlGitHubRepo.value,
authors = developers.value.map(_.name),
language = Some("en"),
title = Some("http4s")
version = Some(version.value.toString)
)
.site
.layout(
Expand All @@ -80,19 +83,16 @@ object Http4sOrgSitePlugin extends AutoPlugin {
)
.site
.favIcons(
Favicon
.external("https://http4s.org/images/http4s-favicon.svg", "32x32", "image/svg+xml")
.copy(sizes = None),
Favicon.external("https://http4s.org/images/http4s-favicon.png", "32x32", "image/png")
Favicon.internal(Root / "images" / "http4s-favicon.svg", "32x32").copy(sizes = None),
Favicon.internal(Root / "images" / "http4s-favicon.png", "32x32")
)
.site
.darkMode
.disabled
.site
.topNavigationBar(
homeLink = ImageLink.external(
"https://http4s.org",
Image.external("https://http4s.org/v1.0/images/http4s-logo-text-dark-2.svg")),
homeLink = ImageLink
.external("https://http4s.org", Image.internal(Root / "images" / "http4s-logo.svg")),
navLinks = tlSiteApiUrl.value.toList.map { url =>
IconLink.external(
url.toString,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2020 http4s.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.http4s.sbt.site

import cats.effect.Resource
import cats.effect.kernel.Sync
import laika.ast.Path
import laika.io.model.InputTree
import laika.rewrite.DefaultTemplatePath
import laika.theme.Theme
import laika.theme.ThemeBuilder
import laika.theme.ThemeProvider

object Http4sHeliumExtensions extends ThemeProvider {

override def build[F[_]](implicit F: Sync[F]): Resource[F, Theme[F]] =
ThemeBuilder[F]("Typelevel Helium Extensions")
.addInputs(
InputTree[F]
.addStream(
F.blocking(getClass.getResourceAsStream("default.template.html")),
DefaultTemplatePath.forHTML
)
.addStream(
F.blocking(getClass.getResourceAsStream("site/styles.css")),
Path.Root / "site" / "styles.css"
)
.addStream(
F.blocking(getClass.getResourceAsStream("images/http4s-favicon.png")),
Path.Root / "images" / "http4s-favicon.png"
)
.addStream(
F.blocking(getClass.getResourceAsStream("images/http4s-favicon.svg")),
Path.Root / "images" / "http4s-favicon.svg"
)
.addStream(
F.blocking(getClass.getResourceAsStream("images/http4s-logo.svg")),
Path.Root / "images" / "http4s-logo.svg"
)
)
.build

}

0 comments on commit 05988b0

Please sign in to comment.