Skip to content
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

Integrate with sbt-typelevel-site #127

Merged
merged 8 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
62 changes: 60 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ jobs:
run: sbt '++${{ matrix.scala }}' unusedCompileDependenciesTest

- name: Make target directories
run: mkdir -p target core/target project/target
run: mkdir -p target core/target site/target project/target

- name: Compress target directories
run: tar cf targets.tar target core/target project/target
run: tar cf targets.tar target core/target site/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -172,3 +172,61 @@ jobs:

- name: Publish
run: sbt '++${{ matrix.scala }}' tlRelease

site:
name: Generate Site
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.15]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 8

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Generate site
run: sbt '++${{ matrix.scala }}' tlSite

- name: Publish site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site/target/docs/site
publish_branch: gh-pages
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# sbt-http4s-org

This project is intended to set up sensible defaults and standards for projects under http4s.org.
If it's useful outside http4s.org, it probably should be pushed further upstream into [sbt-spiewak](https://github.com/djspiewak/sbt-spiewak/).
If it's useful outside http4s.org, it probably should be pushed further upstream into [sbt-typelevel](https://github.com/typelevel/sbt-typelevel).

## Installing it

The plugin is deployed to Sonatype.

```scala
addSbtPlugin("org.http4s" % "sbt-http4s-org" % http4sOrgV)
addSbtPlugin("org.http4s" % "sbt-http4s-org" % "@VERSION@")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is ugly in the GitHub README but it becomes useful information on the live site.

```

## What does it do?
Expand All @@ -17,7 +17,11 @@ addSbtPlugin("org.http4s" % "sbt-http4s-org" % http4sOrgV)

Triggers automatically. Use on all http4s modules.

* Activates the sensible defaults of [sbt-spiewak](https://github.com/djspiewak/sbt-spiewak/)
* Activates the sensible defaults of [sbt-typelevel](https://github.com/typelevel/sbt-typelevel/)
* Sets the organization info
* Enables automated SPDX license headers with appropriate years
* Enables automated license headers with appropriate years
* Enables [sbt-github-actions](https://github.com/djspiewak/sbt-github-actions) with settings appropriate to our workflow

### `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.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ lazy val core = project
name := "sbt-http4s-org"
)

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

ThisBuild / tlBaseVersion := "0.10"
ThisBuild / crossScalaVersions := Seq("2.12.15")
ThisBuild / developers := List(
Expand Down
4 changes: 3 additions & 1 deletion core/build.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.1")
val sbtTypelevelVersion = "0.4.1"
addSbtPlugin("org.typelevel" % "sbt-typelevel" % sbtTypelevelVersion)
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTypelevelVersion)
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")
108 changes: 108 additions & 0 deletions core/src/main/resources/org/http4s/sbt/default.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="${?laika.site.metadata.language}">
<head>
<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" />
<title>${cursor.currentDocument.title}</title>
@:for(laika.site.metadata.authors)
<meta name="author" content="${_}"/>
@:@
@:for(laika.site.metadata.description)
<meta name="description" content="${_}"/>
@:@
@:for(helium.favIcons)
<link rel="icon" @:attribute(sizes, _.sizes) @:attribute(type, _.type) @:attribute(href, _.target)/>
@:@
@:for(helium.webFonts)
<link rel="stylesheet" href="${_}">
@:@
@:linkCSS { paths = ${helium.site.includeCSS} }
@:linkJS { paths = ${helium.site.includeJS} }
@:heliumInitVersions
@:heliumInitPreview(container)
<script> /* for avoiding page load transitions */ </script>
</head>

<body>

<header id="top-bar">

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

${?helium.topBar.home}

${?helium.topBar.links}

</header>

<nav id="sidebar">

<!-- custom start - adjust left navigation - add extra section -->
@:navigationTree {
entries = [
{ target = "/README.md", excludeSections = true }
{ target = "/", excludeRoot = true, excludeSections = true, depth = 2 }
]
}

<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>
</ul>
<!-- custom end -->

</nav>

<div id="container">

<nav id="page-nav">
<p class="header"><a href="#">${cursor.currentDocument.title}</a></p>

@:navigationTree {
entries = [
{ target = "#", excludeRoot = true, depth = 2 }
]
}

<p class="footer">@:for(helium.markupEditLinks)<a href="${_.baseURL}${cursor.currentDocument.path}">${_.icon}${_.text}</a>@:@</p>
</nav>

<main class="content">

${cursor.currentDocument.content}

<!-- 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>.
</footer>
<!-- custom end -->

</main>

</div>

</body>
</html>
9 changes: 9 additions & 0 deletions core/src/main/resources/org/http4s/sbt/site/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
header img {
height: 28px;
width: auto;
margin-top: 6px;
}

#sidebar li.nav-header {
margin-top: -20px;
}
114 changes: 114 additions & 0 deletions core/src/main/scala/org/http4s/sbt/Http4sOrgSitePlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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

import cats.effect.IO
import laika.ast.LengthUnit._
import laika.ast.Path.Root
import laika.ast._
import laika.helium.Helium
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._
import sbt.Keys._
import sbt._

object Http4sOrgSitePlugin extends AutoPlugin {

override def requires = TypelevelSitePlugin && LaikaPlugin

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"
)
},
tlSiteHeliumConfig := {
Helium.defaults.all
.metadata(
language = Some("en"),
title = Some("http4s")
)
.site
.layout(
contentWidth = px(860),
navigationWidth = px(275),
topBarHeight = px(35),
defaultBlockSpacing = px(10),
defaultLineHeight = 1.5,
anchorPlacement = laika.helium.config.AnchorPlacement.Right
)
.site
.themeColors(
primary = Color.hex("5B7980"),
secondary = Color.hex("cc6600"),
primaryMedium = Color.hex("a7d4de"),
primaryLight = Color.hex("e9f1f2"),
text = Color.hex("5f5f5f"),
background = Color.hex("ffffff"),
bgGradient =
(Color.hex("334044"), Color.hex("5B7980")) // only used for landing page background
)
.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")
)
.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")),
navLinks = tlSiteApiUrl.value.toList.map { url =>
IconLink.external(
url.toString,
HeliumIcon.api,
options = Styles("svg-link")
)
} ++ Seq(
IconLink.external(
scmInfo.value.fold("https://github.com/http4s")(_.browseUrl.toString),
HeliumIcon.github,
options = Styles("svg-link")),
IconLink.external("https://discord.gg/XF3CXcMzqD", HeliumIcon.chat),
IconLink.external("https://twitter.com/http4s", HeliumIcon.twitter)
)
)
}
)

}
1 change: 1 addition & 0 deletions docs/README.md
1 change: 0 additions & 1 deletion project/Http4sOrgPlugin.scala

This file was deleted.

File renamed without changes.
10 changes: 10 additions & 0 deletions project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// DO NOT EDIT! This file is auto-generated.

// This plugin enables semantic information to be produced by sbt.
// It also adds support for debugging using the Debug Adapter Protocol

addSbtPlugin("org.scalameta" % "sbt-metals" % "0.11.1")

// This plugin adds the BSP debug capability to sbt server.

addSbtPlugin("ch.epfl.scala" % "sbt-debug-adapter" % "2.0.12")
11 changes: 11 additions & 0 deletions project/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// DO NOT EDIT! This file is auto-generated.

// This plugin enables semantic information to be produced by sbt.
// It also adds support for debugging using the Debug Adapter Protocol

addSbtPlugin("org.scalameta" % "sbt-metals" % "0.11.1")

// This plugin makes sure that the JDI tools are in the sbt classpath.
// JDI tools are used by the debug adapter server.

addSbtPlugin("org.scala-debugger" % "sbt-jdi-tools" % "1.1.1")
1 change: 1 addition & 0 deletions project/src