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

JP - Copying override css and Other improvements #3

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 22 additions & 15 deletions src/main/scala/microsites/Layouts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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",
Expand Down Expand Up @@ -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 }}")
Expand All @@ -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",
Expand All @@ -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();});"))


Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 17 additions & 21 deletions src/main/scala/microsites/MicrositesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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}"
Expand All @@ -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
Expand Down