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

Add setting for path in preview #147

Merged
merged 3 commits into from
May 21, 2019
Merged
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions src/main/scala/com/typesafe/sbt/site/SitePreviewPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object SitePreviewPlugin extends AutoPlugin {
val previewAuto = TaskKey[Unit]("previewAuto", "Launches an automatic jetty server that serves your generated site from the target directory")
val previewFixedPort = SettingKey[Option[Int]]("previewFixedPort") in previewSite
val previewLaunchBrowser = SettingKey[Boolean]("previewLaunchBrowser") in previewSite
val previewPath = SettingKey[String]("previewPath", "path to open on `previewSite` and `previewAuto`") in previewSite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a bit strange that these settings are defined as in previewSite but then are used in both previewSite and previewAuto. But that is for later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
import SitePlugin.autoImport._
import autoImport._
Expand All @@ -22,6 +23,7 @@ object SitePreviewPlugin extends AutoPlugin {
val file = makeSite.value
val portOption = previewFixedPort.value
val browser = previewLaunchBrowser.value
val path = previewPath.value

val port = portOption getOrElse Port.any
val server = createServer(file, port) start()
Expand All @@ -34,22 +36,25 @@ object SitePreviewPlugin extends AutoPlugin {
waitForKey()
}
if(browser)
Browser open ("http://localhost:%d/" format port)
Browser open ("http://localhost:%d/%s".format(port, path))
waitForKey()
server stop()
server destroy()
},
previewAuto := {
val port = previewFixedPort.value getOrElse Port.any
val browser = previewLaunchBrowser.value
val path = previewPath.value

Preview(port, (target in previewAuto).value, makeSite, Compat.genSources, state.value) run { server =>
if (browser)
Browser open(server.portBindings.head.url)
}
Browser open(server.portBindings.head.url + "/" + path)
ennru marked this conversation as resolved.
Show resolved Hide resolved
}
},
previewFixedPort := Some(4000),
previewLaunchBrowser := true,
previewPath := "",
target in previewAuto := siteDirectory.value
)

Expand Down