-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
346 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Release 1.2.0-RC1 | ||
|
||
_Version 1.2.0 is initially coming out in "RC" form due to an upgrade in the `unfiltered` dependency. Please see below._ | ||
|
||
## Enhancements | ||
|
||
1. Support for [Hugo](https://gohugo.io) site generation. Thanks @timperrett! | ||
2. Added `excludeFilter` support to GitBook generator. Thanks @jonas! | ||
3. Added `previewAuto` command, which launches a dynamic HTML server updating content with each modification in site source. Thanks @gsechaud! Note: This change includes an upgrade of the `unfiltered` depenency. Please let us know of any incompatibilities with other plugins that might be caused by this change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
This sbt plugin generates project websites from static content, Jekyll, Sphinx, Pamflet, Nanoc, GitBook, and/or Asciidoctor, and can optionally include generated ScalaDoc. | ||
This sbt plugin generates project websites from static content, Jekyll, Sphinx, Pamflet, Nanoc, GitBook, Paradox, Hugo and/or Asciidoctor, and can optionally include generated ScalaDoc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=0.13.9 | ||
sbt.version=0.13.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/scala/com/typesafe/sbt/site/hugo/HugoPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.typesafe.sbt.site.hugo | ||
|
||
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName | ||
import com.typesafe.sbt.site.SitePreviewPlugin.autoImport.previewFixedPort | ||
import com.typesafe.sbt.site.SitePlugin | ||
import com.typesafe.sbt.site.util.SiteHelpers | ||
import sbt._, Keys._ | ||
import java.net.URI | ||
|
||
object HugoPlugin extends AutoPlugin { | ||
override def requires = SitePlugin | ||
override def trigger = noTrigger | ||
|
||
object autoImport { | ||
val Hugo = config("hugo") | ||
val minimumHugoVersion = settingKey[String]("minimum-hugo-version") | ||
val baseURL = settingKey[URI]("base-url") | ||
val checkHugoVersion = taskKey[Unit]("check-hugo-version") | ||
} | ||
|
||
import autoImport._ | ||
|
||
override def projectSettings = hugoSettings(Hugo) | ||
|
||
/** Creates the settings necessary for running hugo in the given configuration. */ | ||
def hugoSettings(config: Configuration): Seq[Setting[_]] = | ||
inConfig(config)( | ||
Seq( | ||
includeFilter := ("*.html" | "*.png" | "*.js" | "*.css" | "*.gif" | "CNAME"), | ||
minimumHugoVersion := "0.15", | ||
baseURL := new URI(s"http://127.0.0.1:${previewFixedPort.value.getOrElse(1313)}"), | ||
checkHugoVersion := unsafeCheckHugoVersion(minimumHugoVersion.value, streams.value).get, | ||
mappings := { | ||
val _ = checkHugoVersion.value // sadly relying on effects here, as is the idiom in sbt-site | ||
generate(sourceDirectory.value, target.value, includeFilter.value, baseURL.value, streams.value) | ||
}, | ||
siteSubdirName := "" | ||
) | ||
) ++ | ||
SiteHelpers.directorySettings(config) ++ | ||
SiteHelpers.watchSettings(config) ++ | ||
SiteHelpers.addMappingsToSiteDir(mappings in config, siteSubdirName in config) | ||
|
||
/** Run hugo via fork. */ | ||
private[sbt] def generate( | ||
src: File, | ||
target: File, | ||
inc: FileFilter, | ||
baseURL: URI, | ||
s: TaskStreams): Seq[(File, String)] = { | ||
sbt.Process(Seq("hugo", "-d", target.getAbsolutePath, "--baseURL", baseURL.toString), Some(src)) ! s.log match { | ||
case 0 => () | ||
case n => sys.error("Could not run hugo binary, error: " + n) | ||
} | ||
for { | ||
(file, name) <- target ** inc --- target pair relativeTo(target) | ||
} yield file -> name | ||
} | ||
|
||
import scala.util.{Try, Success, Failure} | ||
|
||
def unsafeCheckHugoVersion(minimumVersion: String, s: TaskStreams): Try[Unit] = { | ||
s.log.debug("checking for the installed version of hugo...") | ||
for { | ||
installed <- Try(Seq("hugo", "-", "version").!!) | ||
extracted <- Try("""v(\d\.[1]\d)""".r.findFirstMatchIn(installed.trim)) | ||
_ <- extracted.fold(Failure(new RuntimeException("Hugo is not currently installed!")): Try[Unit] | ||
)(v => if(v.group(1) >= minimumVersion) Success(()) | ||
else Failure(new RuntimeException("The current version of Hugo installed is not new enough to build this project."))) | ||
} yield () | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.typesafe.sbt.site | ||
|
||
import sbt._, Keys._ | ||
import unfiltered.jetty.Server | ||
import unfiltered.filter.Plan | ||
import unfiltered.response._ | ||
import unfiltered.request._ | ||
import java.io.File | ||
import java.io.OutputStream | ||
import collection.mutable.Map | ||
|
||
object Preview { | ||
def apply(port: Int, base: File, genSite: TaskKey[File], genSources: TaskKey[Seq[File]], state: State): Server = { | ||
val rootFile = runTask(genSite, state) | ||
val rootSources = runTask(genSources, state) | ||
|
||
val rootPage: Option[URL] = startPageURL(rootFile) | ||
var mapSources: Map[File, Long] = mapFileToLastModified(rootSources) | ||
|
||
val plan: Plan = unfiltered.filter.Planify { | ||
case GET(unfiltered.request.Path(Seg(path))) => { | ||
val newSources = runTask(genSources, state) | ||
val newMapSources = mapFileToLastModified(newSources) | ||
if(mapSources != newMapSources) { | ||
val _ = runTask(genSite, state) | ||
mapSources = newMapSources | ||
} | ||
path match { | ||
case p :: ps => | ||
val newFile: File = base / path.mkString("/") | ||
responseStreamer(newFile.toURI.toURL) | ||
case Nil => | ||
rootPage match { | ||
case Some(startingPage) => responseStreamer(startingPage) | ||
case None => ResponseString("No file found, make sure to generate any starting web page at root project (default: \"index.html\")") | ||
} | ||
} | ||
} | ||
} | ||
val http = unfiltered.jetty.Server.local(port) | ||
http.plan(plan).resources(new URL(rootFile.toURI.toURL, ".")) | ||
} | ||
|
||
def startPageURL(rootFile: File): Option[URL] = { | ||
val files = rootFile.listFiles.filter(!_.isDirectory) | ||
files.toList.filter(_.getName == "index.html") match { | ||
case ind :: Nil => Some(ind.toURI.toURL) | ||
case Nil if(files.length > 0) => Some(files(0).toURI.toURL) | ||
case _ => None | ||
} | ||
} | ||
|
||
def responseStreamer(url: URL) = | ||
new ResponseStreamer { def stream(os:OutputStream) { | ||
val is = url.openStream | ||
try { | ||
val buf = new Array[Byte](1024) | ||
Iterator.continually(is.read(buf)).takeWhile(_ != -1) | ||
.foreach(os.write(buf, 0, _)) | ||
} finally { | ||
is.close | ||
} | ||
} } | ||
|
||
def mapFileToLastModified(files: Seq[File]): Map[File, Long] = | ||
Map(files.filter(!_.toString.endsWith("~")).map(file => file -> file.lastModified()): _*) | ||
|
||
def runTask[A](task: TaskKey[A], state: State): A = { | ||
val extracted = Project extract state | ||
val (_, result) = extracted.runTask(task, state) | ||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name := "test" | ||
|
||
enablePlugins(HugoPlugin) | ||
|
||
siteSubdirName in Hugo := "thisIsHugo" | ||
|
||
TaskKey[Unit]("checkContent") := { | ||
val dest = (target in makeSite).value / (siteSubdirName in Hugo).value | ||
val index = dest / "index.html" | ||
assert(index.exists, s"${index.getAbsolutePath} did not exist") | ||
val content = IO.readLines(index) | ||
assert(content.exists(_.contains("Knobs")), s"Did not find expected content in:\n${content.mkString("\n")}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % sys.props("project.version")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
baseurl = "http://localhost:1313/" | ||
languageCode = "en-us" | ||
author = "sbt-site" | ||
copyright = "All rights reserved." | ||
|
||
[params] | ||
github_host = "github.com" | ||
github_repository = "verizon/knobs" | ||
project_name = "Knobs" |
Oops, something went wrong.