Skip to content

Commit

Permalink
Merge pull request #200 from Jacoby6000/feature/separate-extra-md-tasks
Browse files Browse the repository at this point in the history
Move extra-md files to a target dir, instead of tut-sources
  • Loading branch information
juanpedromoreno authored Jun 19, 2017
2 parents b0bbb42 + 7a1ff23 commit 5f20f3b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 18 deletions.
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Discussion around sbt-microsites happens in the [Gitter channel](https://gitter.
[GitHub issues](https://github.com/47deg/sbt-microsites/issues) and [pull requests](https://github.com/47deg/sbt-microsites/pulls).

Feel free to open an issue if you notice a bug, have an idea for a feature, or have a question about
the code. Pull requests are also welcome.
the code. Pull requests are also welcome.

When creating a pull request, please be sure to write scripted tests to ensure that your features works.
This project usess the sbt scripted-plugin for testing. Run `sbt scripted` to run scripted tests.

People are expected to follow the [Typelevel Code of Conduct](http://typelevel.org/conduct.html) when discussing sbt-microsites on the Github page, Gitter channel, or other venues.

Expand All @@ -24,4 +27,4 @@ The process is simple:
6. Submit pull request

You will be automatically included in the [AUTHORS.md](AUTHORS.md#contributors) file as contributor in the next release.
If you encounter any confusion or frustration during the contribution process, please create a GitHub issue and we'll do our best to improve the process.
If you encounter any confusion or frustration during the contribution process, please create a GitHub issue and we'll do our best to improve the process.
39 changes: 30 additions & 9 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ trait MicrositeKeys {
val microsite: TaskKey[Seq[File]] = taskKey[Seq[File]]("Create microsite files")
val micrositeConfig: TaskKey[Unit] =
taskKey[Unit]("Copy microsite config to the site folder")
val micrositeMakeExtraMdFiles: TaskKey[File] =
taskKey[File]("Create microsite extra md files")
val micrositeTutExtraMdFiles: TaskKey[Seq[File]] =
taskKey[Seq[File]]("Run tut for extra microsite md files")
val micrositeName: SettingKey[String] = settingKey[String]("Microsite name")
val micrositeDescription: SettingKey[String] = settingKey[String]("Microsite description")
val micrositeAuthor: SettingKey[String] = settingKey[String]("Microsite author")
Expand Down Expand Up @@ -88,6 +92,8 @@ trait MicrositeKeys {
val micrositeExtraMdFiles: SettingKey[Map[File, ExtraMdFileConfig]] =
settingKey[Map[File, ExtraMdFileConfig]](
"Optional. This key is useful when you want to include automatically markdown documents as a part of your microsite, and these files are located in different places from the tutSourceDirectory. The map key is related with the source file, the map value corresponds with the target relative file path and the document meta-information configuration. By default, the map is empty.")
val micrositeExtraMdFilesOutput: SettingKey[File] = settingKey[File](
"Optional. Microsite output location for extra-md files. Default is resourceManaged + '/jekyll/_extra_md'")
val micrositePalette: SettingKey[Map[String, String]] =
settingKey[Map[String, String]]("Microsite palette")
val micrositeFavicons: SettingKey[Seq[MicrositeFavicon]] = settingKey[Seq[MicrositeFavicon]](
Expand Down Expand Up @@ -182,7 +188,8 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
micrositeExternalLayoutsDirectory = micrositeExternalLayoutsDirectory.value,
micrositeExternalIncludesDirectory = micrositeExternalIncludesDirectory.value,
micrositeDataDirectory = micrositeDataDirectory.value,
micrositeExtraMdFiles = micrositeExtraMdFiles.value
micrositeExtraMdFiles = micrositeExtraMdFiles.value,
micrositeExtraMdFilesOutput = micrositeExtraMdFilesOutput.value
),
urlSettings = MicrositeUrlSettings(
micrositeBaseUrl = micrositeBaseUrl.value,
Expand Down Expand Up @@ -219,14 +226,28 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
tutSourceDirectory = (tutSourceDirectory in Compile).value),
micrositeConfig := micrositeHelper.value
.copyConfigurationFile((sourceDirectory in Jekyll).value, siteDirectory.value),
makeMicrosite := Def
.sequential(
microsite,
tut,
makeSite,
micrositeConfig
)
.value,
micrositeMakeExtraMdFiles := micrositeHelper.value.buildAdditionalMd(),
micrositeTutExtraMdFiles := {
val r = (runner in Tut).value
val in = micrositeMakeExtraMdFiles.value
val out = tutTargetDirectory.value
val cp = (fullClasspath in Tut).value
val opts = (scalacOptions in Tut).value
val pOpts = tutPluginJars.value.map(f => "–Xplugin:" + f.getAbsolutePath)
val re = tutNameFilter.value.pattern.toString
_root_.tut.TutPlugin.tutOne(streams.value, r, in, out, cp, opts, pOpts, re).map(_._1)
},
makeMicrosite := {
Def
.sequential(
microsite,
tut,
micrositeTutExtraMdFiles,
makeSite,
micrositeConfig
)
.value
},
publishMicrosite := Def.task {
Command.process(publishMicrositeCommandKey, state.value)
(): Unit
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/microsites/MicrositesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ object MicrositesPlugin extends AutoPlugin {
micrositeExternalIncludesDirectory := (resourceDirectory in Compile).value / "microsite" / "includes",
micrositeDataDirectory := (resourceDirectory in Compile).value / "microsite" / "data",
micrositeExtraMdFiles := Map.empty,
micrositeExtraMdFilesOutput := (resourceManaged in Compile).value / "jekyll" / "_extra_md",
micrositePalette := Map(
"brand-primary" -> "#02B4E5",
"brand-secondary" -> "#1C2C52",
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/microsites/microsites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ case class MicrositeFileLocations(
micrositeExternalLayoutsDirectory: File,
micrositeExternalIncludesDirectory: File,
micrositeDataDirectory: File,
micrositeExtraMdFiles: Map[File, ExtraMdFileConfig])
micrositeExtraMdFiles: Map[File, ExtraMdFileConfig],
micrositeExtraMdFilesOutput: File)

case class MicrositeGitSettings(
githubOwner: String,
Expand Down
18 changes: 14 additions & 4 deletions src/main/scala/microsites/util/MicrositeHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ class MicrositeHelper(config: MicrositeSettings) {
config.fileLocations.micrositeDataDirectory.getAbsolutePath,
s"$targetDir$jekyllDir/_data/")

List(createConfigYML(targetDir), createPalette(targetDir)) ++
createLayouts(targetDir) ++ createPartialLayout(targetDir) ++ createFavicons(targetDir)
}

def buildAdditionalMd(): File = {
val extraMdOutputDir = config.fileLocations.micrositeExtraMdFilesOutput
extraMdOutputDir.mkdirs()

config.fileLocations.micrositeExtraMdFiles foreach {
case (sourceFile, targetFileConfig) =>
println(s"Copying from ${sourceFile.getAbsolutePath} to $tutSourceDir$targetFileConfig")
println(
s"Copying from ${sourceFile.getAbsolutePath} to ${extraMdOutputDir.getAbsolutePath}/$targetFileConfig")

val targetFileContent =
s"""---
Expand All @@ -98,11 +107,12 @@ class MicrositeHelper(config: MicrositeSettings) {
|${Source.fromFile(sourceFile.getAbsolutePath).mkString}
|""".stripMargin

IO.write(s"$tutSourceDir${targetFileConfig.fileName}".toFile, targetFileContent)
val outFile = extraMdOutputDir / targetFileConfig.fileName

IO.write(outFile, targetFileContent)
}

List(createConfigYML(targetDir), createPalette(targetDir)) ++
createLayouts(targetDir) ++ createPartialLayout(targetDir) ++ createFavicons(targetDir)
extraMdOutputDir
}

def createConfigYML(targetDir: String): File = {
Expand Down
3 changes: 3 additions & 0 deletions src/sbt-test/microsites/change-default-paths/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ micrositeExtraMdFiles := Map(
"home"
)
)

micrositeExtraMdFilesOutput := (target in Compile).value / "extra_md_override"

micrositeImgDirectory := (resourceDirectory in Compile).value / "images"
micrositeCssDirectory := (resourceDirectory in Compile).value / "styles"
1 change: 1 addition & 0 deletions src/sbt-test/microsites/change-default-paths/test
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ $ exists target/site/css/palette.css
$ exists target/site/css/style.css
$ exists target/site/css/override-1.css
$ exists target/site/css/override-2.css
$ exists target/extra_md_override/index.md
4 changes: 3 additions & 1 deletion src/test/scala/microsites/util/Arbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ trait Arbitraries {
micrositeExternalIncludesDirectory Arbitrary.arbitrary[File]
micrositeDataDirectory Arbitrary.arbitrary[File]
micrositeExtraMdFiles markdownMapArbitrary.arbitrary
micrositeExtraMdFilesOutput Arbitrary.arbitrary[File]
micrositeBaseUrl Arbitrary.arbitrary[String]
micrositeDocumentationUrl Arbitrary.arbitrary[String]
palette paletteMapArbitrary.arbitrary
Expand Down Expand Up @@ -160,7 +161,8 @@ trait Arbitraries {
micrositeExternalLayoutsDirectory,
micrositeExternalIncludesDirectory,
micrositeDataDirectory,
micrositeExtraMdFiles
micrositeExtraMdFiles,
micrositeExtraMdFilesOutput
),
MicrositeUrlSettings(micrositeBaseUrl, micrositeDocumentationUrl),
MicrositeGitSettings(
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.6.2-SNAPSHOT"
version in ThisBuild := "0.6.2-SNAPSHOT"

0 comments on commit 5f20f3b

Please sign in to comment.