diff --git a/README.md b/README.md index 231d0c39..44cf7109 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,16 @@ micrositeHighlightTheme := "monokai" ``` [Available themes: https://cdnjs.com/libraries/highlight.js/](https://cdnjs.com/libraries/highlight.js/) +- You could add new images to personalize the microsite, you can specify them through the `micrositeImgDirectory` setting. The images in that folder will be automatically copied by the plugin and they will be placed together with the rest of the jekyll resources. By default, its value is `(resourceDirectory in Compile).value / "microsite" / "img"` but you can override it, for instance: +``` +micrositeImgDirectory := (resourceDirectory in Compile).value / "site" / "images" +``` + +- At the same time, you could override the styles through the `micrositeCssDirectory` setting. The css files in that folder will be automatically copied and imported by the plugin in your microsite. The default value is `(resourceDirectory in Compile).value / "microsite" / "css"` but you can override it in this way: +``` +micrositeImgDirectory := (resourceDirectory in Compile).value / "site" / "styles" +``` + - Style uses essentially 8 colors which palette can be set through the setting `micrositePalette` as below: ``` micrositePalette := Map( diff --git a/src/main/scala/microsites/Layouts.scala b/src/main/scala/microsites/Layouts.scala index 2872b3cb..31a9ce8f 100644 --- a/src/main/scala/microsites/Layouts.scala +++ b/src/main/scala/microsites/Layouts.scala @@ -3,11 +3,11 @@ package microsites import scalatags.Text.TypedTag import scalatags.Text.all._ import scalatags.Text.tags2.{title, nav, main, section} - +import FileHelper._ object Layouts { - def home(config: MicrositeConfig): TypedTag[String] = { + def home(config: MicrositeSettings): TypedTag[String] = { html( head( metas(config), @@ -22,7 +22,7 @@ object Layouts { ) } - def metas(config: MicrositeConfig): Seq[TypedTag[String]] = Seq( + def metas(config: MicrositeSettings): Seq[TypedTag[String]] = Seq( meta(charset := "utf-8"), meta(httpEquiv := "X-UA-Compatible", content := "IE=edge,chrome=1"), title(config.name), @@ -40,22 +40,29 @@ object Layouts { meta(name := "twitter:site", content := config.twitter), link(rel := "icon", `type` := "image/png", href := "img/favicon.png")) - def styles(config: MicrositeConfig): Seq[TypedTag[String]] = Seq( - link(rel := "stylesheet", href := "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"), - link(rel := "stylesheet", href := "https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"), - link(rel := "stylesheet", href := s"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/${config.highlightTheme}.min.css"), - link(rel := "stylesheet", href := s"css/style.css"), - link(rel := "stylesheet", href := s"css/palette.css") - ) + def styles(config: MicrositeSettings): Seq[TypedTag[String]] = { + + val customCssList = fetchFilesRecursively(config.micrositeCssDirectory) map { css => + link(rel := "stylesheet", href := s"css/${css.getName}") + } + + Seq( + link(rel := "stylesheet", href := "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"), + link(rel := "stylesheet", href := "https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"), + link(rel := "stylesheet", href := s"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/styles/${config.highlightTheme}.min.css"), + link(rel := "stylesheet", href := s"css/style.css"), + link(rel := "stylesheet", href := s"css/palette.css") + ) ++ customCssList + } - def scripts(config: MicrositeConfig): Seq[TypedTag[String]] = Seq( + def scripts(config: MicrositeSettings): Seq[TypedTag[String]] = Seq( script(src:="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"), script(src:="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"), script(src:="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/highlight.min.js"), script(src:="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.6.0/languages/scala.min.js") ) - def homeHeader(config: MicrositeConfig): TypedTag[String] = header( id:="site-header", + def homeHeader(config: MicrositeSettings): TypedTag[String] = header( id:="site-header", div( cls:="navbar-wrapper", div( cls:="container", div( cls:="row", @@ -89,7 +96,7 @@ object Layouts { ) - def homeMain(config: MicrositeConfig): TypedTag[String] = main(id := "site-main", + def homeMain(config: MicrositeSettings): TypedTag[String] = main(id := "site-main", section(cls := "use", div(cls := "container", div(id := "content", cls := "row", "{{ content }}") @@ -112,7 +119,7 @@ object Layouts { ) ) - def globalFooter(config: MicrositeConfig) = footer( id:="site-footer", + def globalFooter(config: MicrositeSettings) = footer( id:="site-footer", div( cls:="container", div( cls:="row", div( cls:="col-xs-6", @@ -127,7 +134,7 @@ object Layouts { ) ) - def scriptsMain(config:MicrositeConfig): Seq[TypedTag[String]] = scripts(config) ++ + def scriptsMain(config:MicrositeSettings): Seq[TypedTag[String]] = scripts(config) ++ Seq(script("jQuery(document).ready(function(){hljs.initHighlightingOnLoad();});")) diff --git a/src/main/scala/microsites/MicrositeKeys.scala b/src/main/scala/microsites/MicrositeKeys.scala index 9cd6a8bd..cd1c362c 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -10,6 +10,8 @@ trait MicrositeKeys { val micrositeHomepage = settingKey[String]("Microsite homepage") val micrositeTwitter = settingKey[String]("Microsite twitter") val micrositeHighlightTheme = settingKey[String]("Microsite Highlight Theme") + val micrositeImgDirectory = settingKey[File]("Optional. Microsite images directory. By default, it'll be the resourcesDirectory + '/microsite/img'") + val micrositeCssDirectory = settingKey[File]("Optional. Microsite CSS directory. By default, it'll be the resourcesDirectory + '/microsite/css'") val micrositePalette = settingKey[Map[String, String]]("Microsite palette") val micrositeGithubOwner = settingKey[String]("Microsite Github owner") val micrositeGithubRepo = settingKey[String]("Microsite Github repo") diff --git a/src/main/scala/microsites/MicrositeConfig.scala b/src/main/scala/microsites/MicrositeSettings.scala similarity index 67% rename from src/main/scala/microsites/MicrositeConfig.scala rename to src/main/scala/microsites/MicrositeSettings.scala index 8301c7bb..57a15598 100644 --- a/src/main/scala/microsites/MicrositeConfig.scala +++ b/src/main/scala/microsites/MicrositeSettings.scala @@ -1,13 +1,16 @@ package microsites +import sbt._ -case class MicrositeConfig( +case class MicrositeSettings( name: String, description: String, author: String, homepage: String, twitter: String, highlightTheme: String, + micrositeImgDirectory: File, + micrositeCssDirectory: File, palette: Map[String, String], githubOwner: String, githubRepo: String) diff --git a/src/main/scala/microsites/MicrositesPlugin.scala b/src/main/scala/microsites/MicrositesPlugin.scala index 8c8b0c23..8eaf2956 100644 --- a/src/main/scala/microsites/MicrositesPlugin.scala +++ b/src/main/scala/microsites/MicrositesPlugin.scala @@ -28,19 +28,19 @@ object MicrositesPlugin extends AutoPlugin with NativePackagerKeys { Seq( mappings in Universal ++= directory("src/main/resources/microsite"), microsite := createResources( - resourcesDir = (resourceDirectory in Compile).value, - resourceManagedDir = (resourceManaged in Compile).value, - config = MicrositeConfig( + config = MicrositeSettings( name = micrositeName.value, description = micrositeDescription.value, author = micrositeAuthor.value, homepage = micrositeHomepage.value, twitter = micrositeTwitter.value, highlightTheme = micrositeHighlightTheme.value, + micrositeImgDirectory = micrositeImgDirectory.value, + micrositeCssDirectory = micrositeCssDirectory.value, palette = micrositePalette.value, githubOwner = micrositeGithubOwner.value, githubRepo = micrositeGithubRepo.value - )), + ), resourceManagedDir = (resourceManaged in Compile).value), sourceDirectory in Jekyll := resourceManaged.value / "main" / "jekyll", tutSourceDirectory := sourceDirectory.value / "tut", tutTargetDirectory := resourceManaged.value / "main" / "jekyll" @@ -53,6 +53,8 @@ object MicrositesPlugin extends AutoPlugin with NativePackagerKeys { micrositeHomepage := homepage.value.map(_.toString).getOrElse(""), micrositeTwitter := "", micrositeHighlightTheme := "tomorrow", + micrositeImgDirectory := (resourceDirectory in Compile).value / "microsite" / "img", + micrositeCssDirectory := (resourceDirectory in Compile).value / "microsite" / "css", micrositePalette := Map( "brand-primary" -> "#E05236", "brand-secondary" -> "#3F3242", @@ -65,27 +67,21 @@ object MicrositesPlugin extends AutoPlugin with NativePackagerKeys { micrositeGithubOwner := "47deg", micrositeGithubRepo := "sbt-microsites") - object Resolvers { - val allResolvers = Seq( - Resolver.sonatypeRepo("snapshots"), - Resolver.sonatypeRepo("releases")) - } - - def createResources(resourcesDir: File, resourceManagedDir: File, config: MicrositeConfig): Seq[File] = { + def createResources(config: MicrositeSettings, resourceManagedDir: File): Seq[File] = { - val sourceDir = getPathWithSlash(resourcesDir) - val targetDir = getPathWithSlash(resourceManagedDir) + val targetDir: String = getPathWithSlash(resourceManagedDir) + val pluginURL: URL = getClass.getProtectionDomain.getCodeSource.getLocation -// copyPluginResources(getClass.getProtectionDomain.getCodeSource.getLocation, s"${targetDir}jekyll/") - copyPluginResources(getClass.getProtectionDomain.getCodeSource.getLocation, s"${targetDir}jekyll/", "_sass") - copyPluginResources(getClass.getProtectionDomain.getCodeSource.getLocation, s"${targetDir}jekyll/", "css") + copyPluginResources(pluginURL, s"${targetDir}jekyll/", "_sass") + copyPluginResources(pluginURL, s"${targetDir}jekyll/", "css") - copyFilesRecursively(s"${sourceDir}microsite", s"${targetDir}jekyll/img/") + copyFilesRecursively(config.micrositeImgDirectory.getAbsolutePath, s"${targetDir}jekyll/img/") + copyFilesRecursively(config.micrositeCssDirectory.getAbsolutePath, s"${targetDir}jekyll/css/") Seq(createConfigYML(config, targetDir), createLayouts(config, targetDir), createPalette(config, targetDir)) } - def createConfigYML(config: MicrositeConfig, targetDir: String): File = { + def createConfigYML(config: MicrositeSettings, targetDir: String): File = { val targetFile = createFilePathIfNotExists(s"${targetDir}jekyll/_config.yml") IO.write(targetFile, s"""name: ${config.name} |description: "${config.description}" @@ -103,14 +99,14 @@ object MicrositesPlugin extends AutoPlugin with NativePackagerKeys { targetFile } - def createPalette(config: MicrositeConfig, targetDir: String): File = { + def createPalette(config: MicrositeSettings, targetDir: String): File = { val targetFile = createFilePathIfNotExists(s"${targetDir}jekyll/_sass/_variables_palette.scss") - val content = config.palette.map{case (key, value) => s"""$$${key}: $value;"""}.mkString("\n") + val content = config.palette.map{case (key, value) => s"""$$$key: $value;"""}.mkString("\n") IO.write(targetFile, content) targetFile } - def createLayouts(config: MicrositeConfig, targetDir: String): File = { + def createLayouts(config: MicrositeSettings, targetDir: String): File = { val targetFile = createFilePathIfNotExists(s"${targetDir}jekyll/_layouts/home.html") IO.write(targetFile, Layouts.home(config).toString()) targetFile