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

Laika site support for sbt 1.0 #125

Merged
merged 13 commits into from
Feb 12, 2018
10 changes: 9 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ libraryDependencies ++= {
(scalaBinaryVersion in pluginCrossBuild).value
)
)
} else Nil
} else {
Seq(
Defaults.sbtPluginExtra(
"org.planet42" % "laika-sbt" % "0.7.5",
(sbtBinaryVersion in pluginCrossBuild).value,
(scalaBinaryVersion in pluginCrossBuild).value
)
)
}
}

enablePlugins(ParadoxSitePlugin, ParadoxMaterialThemePlugin)
Expand Down
3 changes: 3 additions & 0 deletions notes/1.3.2.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ See the [1.3.2 milestone] for the full list of related tickets and PRs.

1. Bump sbt to 0.13.17 and 1.0.4. [#123] ([@jonas])
2. Bump Paradox to version [0.3.2][paradox-0.3.2]. ([@jonas])
3. Port Laika site plugin to sbt 1.x. [#121] ([@rhpvorderman])

[1.3.2 milestone]: https://github.com/sbt/sbt-site/milestone/6
[#121]: https://github.com/sbt/sbt-site/pull/121
[#123]: https://github.com/sbt/sbt-site/pull/123
[paradox-0.3.2]: https://github.com/lightbend/paradox/releases/tag/v0.3.2

[@jonas]: https://github.com/jonas
[@rhpvorderman]: http://github.com/rhpvorderman
19 changes: 5 additions & 14 deletions src/main/paradox/generators/laika.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Laika

The sbt-site plugin has support for building [Laika] projects.

@@@ note
Currently the Laika generator is only supported for sbt 0.13.
@@@

To enable Laika site generation, simply enable the associated plugin in your `build.sbt` file:

@@ snip[enablePlugin](../../../sbt-test/laika/minimal/build.sbt) { #enablePlugin }
@@ snip[enablePlugin](../../../sbt-test/laika_0.13/minimal/build.sbt) { #enablePlugin }

This plugin assumes you have a Laika project under the `src/laika` directory. To change this, set the `sourceDirectory` key in the `LaikaSite` scope:

Expand All @@ -24,14 +19,10 @@ From other hand you can customize other aspects of Laika's behavior through basi
[Laika sbt plugin](https://planet42.github.io/Laika/using-laika/sbt.html) keys and hooks.
For example in order to add custom block directives you can include such code to your build.sbt:

```sbt
import LaikaKeys._

blockDirectives in Laika += CustomDirectives.postsToc
```

Full sample how use Laika sbt plugin together with sbt-site you can find here:
sbt 0.13
: @@ snip[laikaSbtPluginCustomization](../../../sbt-test/laika_0.13/blog-post/build.sbt) { #laikaSbtPluginCustomization }

@@ snip[laikaSbtPluginCustomization](../../../sbt-test/laika/blog-post/build.sbt) { #laikaSbtPluginCustomization }
sbt 1.x
: @@ snip[laikaSbtPluginCustomization](../../../sbt-test/laika_1.x/blog-post/build.sbt) { #laikaSbtPluginCustomization }

[Laika]: https://github.com/planet42/Laika
3 changes: 1 addition & 2 deletions src/main/paradox/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Before upgrading please consult the @github:[release notes](/notes/). Instructio

@@@ note

* Version 1.3.0 is cross published to both sbt 0.13 and sbt 1.x, however, the
[Laika](generators/laika.md) generator is currently only available for sbt 0.13.
* Version 1.3.0 is cross published to both sbt 0.13 and sbt 1.x.
* As of sbt-site version 1.x.x, sbt version 0.13.10+ or 1.0.0-RC2+ is required.
* For earlier 0.13.x releases, use [version 0.8.2][0.8.2].
* For sbt 0.12, use [version 0.7.2][0.7.2].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.typesafe.sbt.site.laika

import java.io.File

import sbt._
import Keys._
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.util.SiteHelpers
import com.typesafe.sbt.site.SitePlugin.autoImport.siteSubdirName
import com.typesafe.sbt.site.SitePlugin.autoImport.makeSite
import laika.sbt.LaikaPlugin.autoImport.{ Laika, laikaHTML, laikaSite }
import laika.sbt.LaikaPlugin
import Path.relativeTo

object LaikaSitePlugin extends AutoPlugin {
override def requires = SitePlugin && LaikaPlugin
override def trigger = noTrigger

object autoImport {
val LaikaSite = config("laikaSite")
}
import autoImport._

override def projectSettings = laikaSettings(LaikaSite)

/** Creates settings necessary for running Laika in the given configuration. */
def laikaSettings(config: Configuration): Seq[Setting[_]] =
inConfig(config)(
Def.settings(
LaikaPlugin.projectSettings,
target in laikaSite := target.value,
includeFilter := AllPassFilter,
excludeFilter := HiddenFileFilter,
mappings := {
generate(laikaSite.value, includeFilter.value, excludeFilter.value)
},
siteSubdirName := "",
sourceDirectories in Laika := Seq(sourceDirectory.value)
)
) ++
SiteHelpers.directorySettings(config) ++
SiteHelpers.watchSettings(config) ++
SiteHelpers.addMappingsToSiteDir(mappings in config, siteSubdirName in config)

private def generate(target: File, inc: FileFilter, exc: FileFilter): Seq[(File, String)] = {
// Figure out what was generated.
val files = (target ** inc) --- (target ** exc) --- target
files pair relativeTo(target)
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions src/sbt-test/laika_1.x/blog-post/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Based on [Blog Post](http://startbootstrap.com/template-overviews/blog-post/) and adopted for Laika just as sample
31 changes: 31 additions & 0 deletions src/sbt-test/laika_1.x/blog-post/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name := "test"

//#enablePlugin
enablePlugins(LaikaSitePlugin)
//#enablePlugin

sourceDirectory in LaikaSite := sourceDirectory.value / "blog"

siteSubdirName in LaikaSite := "blog"

//#laikaSbtPluginCustomization
laikaBlockDirectives in LaikaSite += CustomDirectives.postsToc
laikaSiteRenderers in LaikaSite += CustomDirectives.postsRenderer
//#laikaSbtPluginCustomization

TaskKey[Unit]("checkContent") := {
val dest = (target in makeSite).value / (siteSubdirName in LaikaSite).value

val expectedFilesAndWords = Map(
dest / "index.html" -> Seq("Start Bootstrap Template", "Blog Post Title", "Second Post Title"),
dest / "topics" / "post-1.html" -> Seq("Blog Post Title", "recusandae laborum minus inventore?"),
dest / "topics" / "post-2.html" -> Seq("Second Post Title", "perspiciatis. Enim, iure!")
)

for ((file, words) <- expectedFilesAndWords) {
assert(file.exists, s"${file.getAbsolutePath} did not exist")
val content = IO.readLines(file)
for (word <- words)
assert(content.exists(_.contains(word)), s"Did not find $word content in:\n${content.mkString("\n")}")
}
}
55 changes: 55 additions & 0 deletions src/sbt-test/laika_1.x/blog-post/project/CustomDirectives.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import laika.directive.Directives.Blocks
import laika.directive.StandardDirectives
import laika.render.HTMLWriter
import laika.rewrite.{DocumentCursor, TreeCursor}
import laika.tree.Documents.{Document, DocumentTree}
import laika.tree.Elements
import laika.tree.Elements._
import com.typesafe.config.Config

// Just sample, probably not the best way to do custom toc for Laika
object CustomDirectives extends StandardDirectives {

case class PostsTocElement(title: Seq[Span], by: String, path: PathInfo, options: Elements.Options)
extends Elements.Element with Elements.Block

val postsToc: Blocks.Directive = Blocks.create("postsToc") {
import Blocks.Combinators._

def titleOrName (content: Document) =
if (content.title.nonEmpty) content.title
else Seq(Text(content.name))

def by(config: Config) =
if (config.hasPath("by"))
config.getString("by")
else ""

cursor.map { cursor =>
val posts = cursor.root.children.collect {
case pd: TreeCursor =>
pd.children.collect {
case d: DocumentCursor =>
val path = d.target.path
val refPath = cursor.parent.target.path
PostsTocElement(titleOrName(d.target),
by(d.config),
PathInfo.fromPath(path, refPath.parent),
Styles("toc"))
}
}.flatten

BlockSequence(posts)
}
}

val postsRenderer: HTMLWriter => RenderFunction = { out => {
case PostsTocElement(title, by, path, options) =>
out << Paragraph(List(
CrossLink(title, "", path),
LineBreak(),
SpanSequence(Seq(Text("by "), Text(by)))
), options)
}
}
}
1 change: 1 addition & 0 deletions src/sbt-test/laika_1.x/blog-post/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.0.2
1 change: 1 addition & 0 deletions src/sbt-test/laika_1.x/blog-post/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % sys.props("project.version"))
159 changes: 159 additions & 0 deletions src/sbt-test/laika_1.x/blog-post/src/blog/default.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>{{document.title}}</title>

<!-- Bootstrap Core CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Custom CSS -->
<style>
body {
padding-top: 70px;
}
footer {
margin: 50px 0;
}
toc
</style>

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</head>

<body>

<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>

<!-- Page Content -->
<div class="container">

<div class="row">

<div class="col-lg-8">

{{document.content}}

</div>

<!-- Blog Sidebar Widgets Column -->
<div class="col-md-4">

<!-- Blog Search Well -->
<div class="well">
<h4>Blog Search</h4>
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<!-- /.input-group -->
</div>

<!-- Blog Categories Well -->
<div class="well">
<h4>Blog Categories</h4>
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled">
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled">
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
</ul>
</div>
</div>
<!-- /.row -->
</div>

</div>

</div>
<!-- /.row -->

<hr>

<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright &copy; Your Website 2014</p>
</div>
</div>
<!-- /.row -->
</footer>

</div>
<!-- /.container -->

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>

</html>
5 changes: 5 additions & 0 deletions src/sbt-test/laika_1.x/blog-post/src/blog/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%
title: "Blog Post - Start Bootstrap Template"
%}

@:postsToc.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
navigationOrder = [
post-1.md
post-2.md
]
Loading