diff --git a/docs/src/main/paradox/configuration.md b/docs/src/main/paradox/configuration.md index c0a33c19..5188536a 100644 --- a/docs/src/main/paradox/configuration.md +++ b/docs/src/main/paradox/configuration.md @@ -29,12 +29,13 @@ If a file duplicate exist between the directories, the overlay file is dropped i ## Multi Configuration -Paradox supports multiple sbt configurations. Each configuration is by default located to `src/configName` of the project, -with the target directory defined as `target/paradox/site/configName`, `configName` corresponding to configuration.name of -a particular configuration. There still remains the usual main project in `src/main` of course if you don't need multiple -paradox project directories. +By default, Paradox expects documentation source files in the `src/main/paradox` directory. +For situations where different parts of the documentation are stored separately, Paradox supports custom sbt configuration scopes. +Each custom configuration source files are by default located in the `src//paradox` directory. +The target directory is defined as `target/paradox/site/`. +Here `` corresponds to `configuration.name` of a particular configuration. -To associate a configuration to paradox, use its settings, and change its default source and/or target directorie(s) if needed: +To associate a configuration to paradox, manually add settings from `ParadoxPlugin.paradoxSettings`, and change its default source and/or target directories if needed: ```scala val SomeConfig = config("some-config") @@ -49,7 +50,8 @@ lazy val root = (project in file(".")). ) ``` -Now, either you run paradox on one configuration; "sbt someConfig:paradox" or you can run the main project with the usual way; "sbt paradox". +Now, to run paradox for custom configuration execute `sbt someConfig:paradox`. +It is still possible to run paradox for the main configuration the usual way `sbt paradox`. ## Version warning diff --git a/plugin/src/main/scala/com/lightbend/paradox/sbt/ParadoxPlugin.scala b/plugin/src/main/scala/com/lightbend/paradox/sbt/ParadoxPlugin.scala index dd2b9a91..b71d8374 100644 --- a/plugin/src/main/scala/com/lightbend/paradox/sbt/ParadoxPlugin.scala +++ b/plugin/src/main/scala/com/lightbend/paradox/sbt/ParadoxPlugin.scala @@ -114,7 +114,7 @@ object ParadoxPlugin extends AutoPlugin { excludeFilter in paradoxMarkdownToHtml := HiddenFileFilter, sources in paradoxMarkdownToHtml := Defaults.collectFiles(sourceDirectories in paradox, includeFilter in paradoxMarkdownToHtml, excludeFilter in paradoxMarkdownToHtml).value, mappings in paradoxMarkdownToHtml := Defaults.relativeMappings(sources in paradoxMarkdownToHtml, sourceDirectories in paradox).value, - target in paradoxMarkdownToHtml := target.value / "paradox" / "html", + target in paradoxMarkdownToHtml := target.value / "paradox" / "html" / configTarget(configuration.value), managedSourceDirectories in paradoxTheme := paradoxTheme.value.toSeq.map { theme => (WebKeys.webJarsDirectory in Assets).value / (WebKeys.webModulesLib in Assets).value / theme.name @@ -130,7 +130,7 @@ object ParadoxPlugin extends AutoPlugin { // if there are duplicates, select the file from the local template to allow overrides/extensions in themes WebKeys.deduplicators in paradoxTheme += SbtWeb.selectFileFrom((sourceDirectory in paradoxTheme).value), mappings in paradoxTheme := SbtWeb.deduplicateMappings((mappings in paradoxTheme).value, (WebKeys.deduplicators in paradoxTheme).value), - target in paradoxTheme := target.value / "paradox" / "theme", + target in paradoxTheme := target.value / "paradox" / "theme" / configTarget(configuration.value), paradoxThemeDirectory := SbtWeb.syncMappings(WCompat.cacheStore(streams.value, "paradox-theme"), (mappings in paradoxTheme).value, (target in paradoxTheme).value), paradoxTemplate := { @@ -185,13 +185,7 @@ object ParadoxPlugin extends AutoPlugin { val themeFilter = (managedSourceDirectories in paradoxTheme).value.headOption.map(InDirectoryFilter).getOrElse(NothingFilter) (mappings in Assets).value filterNot { case (file, path) => themeFilter.accept(file) } }, - target in paradox := { - val config = configuration.value - if (config.name != Compile.name) - target.value / "paradox" / "site" / config.name - else - target.value / "paradox" / "site" / "main" - }, + target in paradox := target.value / "paradox" / "site" / configTarget(configuration.value), watchSources in Defaults.ConfigGlobal ++= Compat.sourcesFor((sourceDirectories in paradox).value), @@ -200,6 +194,10 @@ object ParadoxPlugin extends AutoPlugin { paradox := SbtWeb.syncMappings(WCompat.cacheStore(streams.value, "paradox"), (mappings in paradox).value, (target in paradox).value) ) + private def configTarget(config: Configuration) = + if (config.name == Compile.name) "main" + else config.name + def shortVersion(version: String): String = version.replace("-SNAPSHOT", "*") def dateProperties: Map[String, String] = { diff --git a/plugin/src/sbt-test/paradox/custom-configuration/build.sbt b/plugin/src/sbt-test/paradox/custom-configuration/build.sbt new file mode 100644 index 00000000..e40f762c --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/build.sbt @@ -0,0 +1,23 @@ +val Docs1 = config("docs1") +val Docs2 = config("docs2") + +enablePlugins(ParadoxPlugin) + +ParadoxPlugin.paradoxSettings(Docs1) +ParadoxPlugin.paradoxSettings(Docs2) + +TaskKey[Unit]("makeDocs") := { + (Docs1 / paradox).value + (Docs2 / paradox).value +} + +TaskKey[Unit]("check") := { + def checkFileContent(file: File, expected: String) = { + assert(file.exists, s"${file.getAbsolutePath} does not exists") + val contents = IO.readLines(file) + assert(contents.exists(_.contains(expected)), s"Did not find '$expected' in\n${contents.mkString("\n")}") + } + + checkFileContent((Docs1 / paradox / target).value / "index.html", "Docs1 index") + checkFileContent((Docs2 / paradox / target).value / "index.html", "Docs2 index") +} diff --git a/plugin/src/sbt-test/paradox/custom-configuration/project/build.properties b/plugin/src/sbt-test/paradox/custom-configuration/project/build.properties new file mode 100644 index 00000000..c0bab049 --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.2.8 diff --git a/plugin/src/sbt-test/paradox/custom-configuration/project/plugins.sbt b/plugin/src/sbt-test/paradox/custom-configuration/project/plugins.sbt new file mode 100644 index 00000000..be8b011a --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % sys.props("project.version")) diff --git a/plugin/src/sbt-test/paradox/custom-configuration/src/docs1/paradox/index.md b/plugin/src/sbt-test/paradox/custom-configuration/src/docs1/paradox/index.md new file mode 100644 index 00000000..d7108780 --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/src/docs1/paradox/index.md @@ -0,0 +1 @@ +Docs1 index. diff --git a/plugin/src/sbt-test/paradox/custom-configuration/src/docs2/paradox/index.md b/plugin/src/sbt-test/paradox/custom-configuration/src/docs2/paradox/index.md new file mode 100644 index 00000000..7a582ee8 --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/src/docs2/paradox/index.md @@ -0,0 +1 @@ +Docs2 index. diff --git a/plugin/src/sbt-test/paradox/custom-configuration/test b/plugin/src/sbt-test/paradox/custom-configuration/test new file mode 100644 index 00000000..0afa4704 --- /dev/null +++ b/plugin/src/sbt-test/paradox/custom-configuration/test @@ -0,0 +1,2 @@ +> makeDocs +> check