Skip to content

Commit

Permalink
publishMultiversionMicrosite and fix GHPagesPlugin publishing (#388)
Browse files Browse the repository at this point in the history
* Change return value in pushMicrosite GHPagesPlugin case.

* Override ghpagesPrivateMappings task, to set own build site directory.

* Create new publishMultiversionMicrosite task to publish exactly that :)

* Update docs.

* Fix typo in error message.
  • Loading branch information
calvellido authored Dec 4, 2019
1 parent 10d5296 commit fa2f859
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
8 changes: 7 additions & 1 deletion docs/docs/docs/build-the-microsite.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ Once both requirements are satisfied, you can just run:
sbt> publishMicrosite
```

And that's all. Behind the scenes, `makeMicrosite` and `pushSite` are invoked.
or

```bash
sbt> publishMultiversionMicrosite
```

And that's all. Behind the scenes, `makeMicrosite` or `makeMultiversionMicrosite`, and `pushSite` are invoked.

By default, the second task uses the [`sbt-ghpages` plugin](https://github.com/sbt/sbt-ghpages).

Expand Down
31 changes: 21 additions & 10 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

package microsites

import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport.{
ghpagesBranch,
ghpagesNoJekyll,
ghpagesPushSite
}
import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport._
import com.typesafe.sbt.site.SitePlugin.autoImport.makeSite
import microsites.util.MicrositeHelper
import io.circe._
Expand Down Expand Up @@ -92,6 +88,8 @@ trait MicrositeKeys {
taskKey[Unit]("Task to just push files up.")
val publishMicrosite: TaskKey[Unit] =
taskKey[Unit]("Task helper that wraps the `publishMicrositeCommand`.")
val publishMultiversionMicrosite: TaskKey[Unit] =
taskKey[Unit]("Task helper that wraps the `publishMultiversionMicrositeCommand`.")
val microsite: TaskKey[Seq[File]] = taskKey[Seq[File]]("Create microsite files")
val micrositeMakeExtraMdFiles: TaskKey[File] =
taskKey[File]("Create microsite extra md files")
Expand Down Expand Up @@ -177,8 +175,9 @@ trait MicrositeKeys {
"Optional. Customize the second line in the footer."
)

val pushMicrositeCommandKey: String = "pushMicrositeCommand"
val publishMicrositeCommandKey: String = "publishMicrositeCommand"
val pushMicrositeCommandKey: String = "pushMicrositeCommand"
val publishMicrositeCommandKey: String = "publishMicrositeCommand"
val publishMultiversionMicrositeCommandKey: String = "publishMultiversionMicrositeCommand"

val micrositeEditButton: SettingKey[Option[MicrositeEditButton]] =
settingKey[Option[MicrositeEditButton]](
Expand Down Expand Up @@ -450,6 +449,9 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
makeMultiversionMicrosite := {
Def.sequential(createMicrositeVersions, clean, makeVersionedMicrosite, moveMicrositeVersions)
}.value,
ghpagesPrivateMappings := {
sbt.Path.allSubpaths((target in makeSite).value).toList
},
pushMicrosite := {
val siteDir: File = (target in makeSite).value
val noJekyll: Boolean = ghpagesNoJekyll.value
Expand All @@ -463,8 +465,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
lazy val log: Logger = streams.value.log

(pushSiteWith.name, gitHosting.name) match {
case (GHPagesPlugin.name, _) =>
Def.task(ghpagesPushSite.value)
case (GHPagesPlugin.name, _) => ghpagesPushSite.value
case (GitHub4s.name, GitHub.name) if githubToken.nonEmpty =>
val commitMessage = sys.env.getOrElse("SBT_GHPAGES_COMMIT_MESSAGE", "updated site")

Expand All @@ -486,14 +487,17 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
log.error(
s"You must provide a GitHub token through the `micrositeGithubToken` setting for pushing with github4s")
case (GitHub4s.name, hosting) =>
log.warn(s"github4s doens't have support for $hosting")
log.warn(s"github4s doesn't have support for $hosting")
case _ =>
log.error(
s"""Unexpected match case (pushSiteWith, gitHosting) = ("${pushSiteWith.name}", "${gitHosting.name}")""")
}
},
publishMicrosite := {
Def.sequential(clean, makeMicrosite, pushMicrosite)
}.value,
publishMultiversionMicrosite := {
Def.sequential(clean, makeMultiversionMicrosite, pushMicrosite)
}.value
)

Expand All @@ -511,6 +515,13 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
extracted.runTask(publishMicrosite, st)._1
}

val publishMultiversionMicrositeCommand: Command =
Command(publishMultiversionMicrositeCommandKey)(_ => OptNotSpace) { (st, _) =>
val extracted = Project.extract(st)

extracted.runTask(publishMultiversionMicrosite, st)._1
}

private[this] def validFile(extension: String)(file: File): Boolean =
file.getName.endsWith(s".$extension")
}

0 comments on commit fa2f859

Please sign in to comment.