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

Reviving NanocPlugin #212

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions .github/workflows/check-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- { sbtCrossVersion: "1.4.9", jvmName: "temurin:1.11.0" }
# { jvmName: "temurin:1.11.0" }
# { jvmName: "temurin:1.17.0" }
sbtCrossVersion: ["1.4.9"]
jvmName: ["temurin:1.11.0","temurin:1.17.0"]
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
Expand Down Expand Up @@ -49,7 +47,7 @@ jobs:

- name: Install Jekyll, Nanoc, Asciidoctor
run: |-
sudo gem install jekyll:3.8.4 nanoc:4.0.2 asciidoctor --no-document
sudo gem install jekyll:3.8.4 nanoc:4.1.2 asciidoctor --no-document
# npm install -g gitbook-cli@2.3.2
# gitbook install 3.2.3

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
target
.bsp
4 changes: 4 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 3.7.12
runner.dialect = scala213
align.preset = more
maxColumn = 120
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# sbt-site

This sbt plugin generates project websites from static content, [GitBook], [Paradox], and/or [Asciidoctor], and can optionally include generated Scaladoc. It is designed to work hand-in-hand with publishing plugins like [sbt-ghpages].
This sbt plugin generates project websites from static content, [GitBook], [Paradox], [Nanoc], and/or [Asciidoctor], and can optionally include generated Scaladoc. It is designed to work hand-in-hand with publishing plugins like [sbt-ghpages].

For version 1.5.0 we removed the integrations with [Jekyll], [Sphinx], [Pamflet], [Nanoc], [Hugo], and [Laika] as they require updates. Please see the ["revive" issues](https://github.com/sbt/sbt-site/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+revive).
For version 1.5.0 we removed the integrations with [Jekyll], [Sphinx], [Pamflet], [Hugo], and [Laika] as they require updates. Please see the ["revive" issues](https://github.com/sbt/sbt-site/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+revive).

## Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ trait AsciidoctorKeys {
val asciidoctorAttributes = SettingKey[Map[String, String]](
"asciidoctor-attributes",
"Asciidoctor allows the rendering process to be influenced by so-called attributes. " +
"You can read more about attributes here: https://asciidoctor.org/docs/user-manual/#attributes")
"You can read more about attributes here: https://asciidoctor.org/docs/user-manual/#attributes"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import sbt._
/** Asciidoctor generator. */
object AsciidoctorPlugin extends AutoPlugin {
override def requires = SitePlugin
override def trigger = noTrigger
override def trigger = noTrigger

object autoImport extends AsciidoctorKeys {
val Asciidoctor = config("asciidoctor")
Expand All @@ -36,7 +36,8 @@ object AsciidoctorPlugin extends AutoPlugin {
target.value,
includeFilter.value,
version.value,
asciidoctorAttributes.value),
asciidoctorAttributes.value
),
siteSubdirName := ""
)
) ++
Expand All @@ -50,7 +51,8 @@ object AsciidoctorPlugin extends AutoPlugin {
output: File,
includeFilter: FileFilter,
version: String,
userSetAsciidoctorAttributes: Map[String, String]): Seq[(File, String)] = {
userSetAsciidoctorAttributes: Map[String, String]
): Seq[(File, String)] = {
val oldContextClassLoader = Thread.currentThread().getContextClassLoader
Thread.currentThread().setContextClassLoader(this.getClass.getClassLoader)
val asciidoctor = Factory.create()
Expand All @@ -61,8 +63,8 @@ object AsciidoctorPlugin extends AutoPlugin {
options.setDestinationDir(output.getAbsolutePath)
options.setSafe(SafeMode.UNSAFE)

//pass project.version to asciidoctor as attribute project-version
//need to do this explicitly through HashMap because otherwise JRuby complains
// pass project.version to asciidoctor as attribute project-version
// need to do this explicitly through HashMap because otherwise JRuby complains
val attributes = new util.HashMap[String, AnyRef]()
attributes.put("project-version", version)

Expand Down
85 changes: 56 additions & 29 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
inThisBuild(Seq(
organization := "com.github.sbt",
organizationName := "sbt",
organizationHomepage := Some(url("https://www.scala-sbt.org/")),

homepage := Some(url("https://www.scala-sbt.org/sbt-site/")),
licenses += ("BSD 3-Clause", url("https://opensource.org/licenses/BSD-3-Clause")),
//#scm-info
scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-site"), "scm:git:git@github.com:sbt/sbt-site.git")),
//#scm-info
developers += Developer(
"contributors",
"Contributors",
"https://gitter.im/sbt/sbt-site",
url("https://github.com/sbt/sbt-site/graphs/contributors")
),
resolvers ++= Resolver.sonatypeOssRepos("releases")
))
inThisBuild(
Seq(
organization := "com.github.sbt",
organizationName := "sbt",
organizationHomepage := Some(url("https://www.scala-sbt.org/")),
homepage := Some(url("https://www.scala-sbt.org/sbt-site/")),
licenses += ("BSD 3-Clause", url(
"https://opensource.org/licenses/BSD-3-Clause"
)),
// #scm-info
scmInfo := Some(
ScmInfo(
url("https://github.com/sbt/sbt-site"),
"scm:git:git@github.com:sbt/sbt-site.git"
)
),
// #scm-info
developers += Developer(
"contributors",
"Contributors",
"https://gitter.im/sbt/sbt-site",
url("https://github.com/sbt/sbt-site/graphs/contributors")
),
resolvers ++= Resolver.sonatypeOssRepos("releases")
)
)

val pluginSettings = Seq(
sbtPlugin := true,
sbtPlugin := true,
crossSbtVersions := List("1.4.9"),
scriptedLaunchOpts += "-Dproject.version=" + version.value
// scriptedBufferLog := false
Expand All @@ -37,23 +45,32 @@ val commonSettings = Seq(

val unfilteredVersion = "0.10.4"

addCommandAlias("prepare", ";+clean;+scalafmtAll;+compile;+test;+scripted")

lazy val root = project
.in(file("."))
.settings(
publish / skip := true,
publish / skip := true,
Compile / publishArtifact := false
)
.settings(
name := "sbt-site-root",
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo"))),
publishTo := Some(
Resolver.file("Unused transient repository", file("target/unusedrepo"))
),
Compile / paradoxMaterialTheme ~= {
_.withFavicon("img/favicon.png")
.withLogo("img/sbt-logo.svg")
.withRepository(uri("https://github.com/sbt/sbt-site"))
}
)
.aggregate(core, asciidoctor, gitbook, paradox)
.enablePlugins(SitePreviewPlugin, ParadoxSitePlugin, ParadoxMaterialThemePlugin)
.aggregate(core, asciidoctor, gitbook, paradox, nanoc)
.enablePlugins(
SitePreviewPlugin,
ParadoxSitePlugin,
ParadoxMaterialThemePlugin,
NanocPlugin
)

lazy val core = project
.in(file("core"))
Expand All @@ -64,9 +81,9 @@ lazy val core = project
name := "sbt-site",
libraryDependencies ++= Seq(
"ws.unfiltered" %% "unfiltered-directives" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-filter" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-jetty" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-specs2" % unfilteredVersion % Test,
"ws.unfiltered" %% "unfiltered-filter" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-jetty" % unfilteredVersion,
"ws.unfiltered" %% "unfiltered-specs2" % unfilteredVersion % Test
).map(
// Force sbt-site to Scala XML 2.1
_.exclude("org.scala-lang.modules", "scala-xml_2.12")
Expand All @@ -80,7 +97,7 @@ lazy val asciidoctor = project
.settings(
name := "sbt-site-asciidoctor",
libraryDependencies ++= Seq(
"org.asciidoctor" % "asciidoctorj" % "2.1.0",
"org.asciidoctor" % "asciidoctorj" % "2.1.0",
"org.asciidoctor" % "asciidoctorj-diagram" % "1.5.18"
)
)
Expand Down Expand Up @@ -117,8 +134,18 @@ lazy val gitbook = project
// (pluginCrossBuild / scalaBinaryVersion).value
// )

// https://github.com/sbt/sbt-site/issues/205
// lazy val nanoc = project...
lazy val nanoc = project
.in(file("nanoc"))
.settings(
name := "sbt-site-nanoc",
libraryDependencies ++= Seq(
"org.yaml" % "snakeyaml" % "2.0"
)
)
.dependsOn(core)
.enablePlugins(SbtPlugin)
.settings(pluginSettings)
.settings(commonSettings)

// https://github.com/sbt/sbt-site/issues/206
// lazy val pamflet = project...
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/com/typesafe/sbt/SbtSite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.typesafe.sbt
import com.typesafe.sbt.site.SitePlugin
import sbt.Keys

/** Shim for backwards compatibility in `sbt-ghpages`*/
/** Shim for backwards compatibility in `sbt-ghpages` */
object SbtSite {
object SiteKeys {
@deprecated("Please upgrade to AutoPlugin and use `makeSite / mappings`", "1.0")
Expand Down
46 changes: 28 additions & 18 deletions core/src/main/scala/com/typesafe/sbt/site/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ object Compat {
val Process = scala.sys.process.Process
type ProcessLogger = scala.sys.process.ProcessLogger

def cached(cacheBaseDirectory: File, inStyle: Style, outStyle: Style)(action: (ChangeReport[File], ChangeReport[File]) => Set[File]): Set[File] => Set[File] =
sbt.util.FileFunction.cached(CacheStoreFactory(cacheBaseDirectory), inStyle = inStyle, outStyle = outStyle)(action = action)
def cached(cacheBaseDirectory: File, inStyle: Style, outStyle: Style)(
action: (ChangeReport[File], ChangeReport[File]) => Set[File]
): Set[File] => Set[File] =
sbt.util.FileFunction.cached(CacheStoreFactory(cacheBaseDirectory), inStyle = inStyle, outStyle = outStyle)(action =
action
)

val genSources: State => Seq[File] = {
import scala.collection.JavaConverters._
Expand All @@ -27,26 +31,32 @@ object Compat {
src => f.get(src).asInstanceOf[A]
}

val baseField = sourceField[File]("base")
val baseField = sourceField[File]("base")
val includeField = sourceField[FileFilter]("includeFilter")
val excludeField = sourceField[FileFilter]("excludeFilter")

(s: State) => Preview.runTask(watchSources, s).flatMap { src =>
val base = baseField(src)
val include = includeField(src)
val exclude = excludeField(src)

try {
Files.find(
base.toPath,
64,
(f, _) => include.accept(f.toFile) && !exclude.accept(f.toFile)
).iterator().asScala.map(_.toFile).toList
} catch {
case _: java.nio.file.NoSuchFileException =>
Nil
(s: State) =>
Preview.runTask(watchSources, s).flatMap { src =>
val base = baseField(src)
val include = includeField(src)
val exclude = excludeField(src)

try {
Files
.find(
base.toPath,
64,
(f, _) => include.accept(f.toFile) && !exclude.accept(f.toFile)
)
.iterator()
.asScala
.map(_.toFile)
.toList
} catch {
case _: java.nio.file.NoSuchFileException =>
Nil
}
}
}
}

def watchSettings(scope: Scope): Seq[Setting[_]] =
Expand Down
21 changes: 11 additions & 10 deletions core/src/main/scala/com/typesafe/sbt/site/SiteKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package com.typesafe.sbt.site
import sbt.Keys._
import sbt._

/**
* Top-level keys.
* @since 10/29/15
*/
/** Top-level keys.
* @since 10/29/15
*/
trait SiteKeys {
val makeSite = TaskKey[File]("make-site", "Generates a static website for a project.")
val makeSite = TaskKey[File]("make-site", "Generates a static website for a project.")
val packageSite = TaskKey[File]("package-site", "Create a zip file of the website.")
val siteSubdirName = SettingKey[String]("siteSubdirName",
"Name of subdirectory in site target directory to put generator plugin content. Defaults to empty string.")
val siteMappings = makeSite / mappings
val siteDirectory = makeSite / target
val siteSources = makeSite / sources
val siteSubdirName = SettingKey[String](
"siteSubdirName",
"Name of subdirectory in site target directory to put generator plugin content. Defaults to empty string."
)
val siteMappings = makeSite / mappings
val siteDirectory = makeSite / target
val siteSources = makeSite / sources
val siteSourceDirectory = makeSite / sourceDirectory
}
12 changes: 6 additions & 6 deletions core/src/main/scala/com/typesafe/sbt/site/SitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ object SitePlugin extends AutoPlugin {
override def trigger = allRequirements
object autoImport extends SiteKeys {
def publishSite(): SettingsDefinition = addArtifact(packageSite / artifact, packageSite)
val addMappingsToSiteDir = com.typesafe.sbt.site.util.SiteHelpers.addMappingsToSiteDir _
val addMappingsToSiteDir = com.typesafe.sbt.site.util.SiteHelpers.addMappingsToSiteDir _
}
import autoImport._

override lazy val projectSettings = Seq(
siteMappings := Seq.empty,
siteMappings := (siteMappings ?? Seq.empty).value,
siteDirectory := target.value / "site",
siteSourceDirectory := sourceDirectory.value / "site",
siteMappings := Seq.empty,
siteMappings := (siteMappings ?? Seq.empty).value,
siteDirectory := target.value / "site",
siteSourceDirectory := sourceDirectory.value / "site",
makeSite / includeFilter := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf",
siteMappings ++= SiteHelpers.selectSubpaths(siteSourceDirectory.value, (makeSite / includeFilter).value),
makeSite := SiteHelpers.copySite(siteDirectory.value, streams.value.cacheDirectory, siteMappings.value),
packageSite / artifact := SiteHelpers.siteArtifact(moduleName.value),
packageSite / artifact := SiteHelpers.siteArtifact(moduleName.value),
packageSite / artifactPath := Defaults.artifactPathSetting(packageSite / artifact).value,
packageSite := SiteHelpers.createSiteZip(makeSite.value, (packageSite / artifactPath).value, streams.value)
)
Expand Down
Loading