From 68c69661364507dc7a0aca4500b7442b1395ace4 Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Wed, 21 Aug 2019 05:53:13 +0000 Subject: [PATCH] Added gitpod config --- .gitpod.yml | 12 ++++++++++++ README.md | 13 +++++++++++-- src/cmd/serve.rs | 21 ++++++++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..85fbc13a --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,12 @@ +ports: +- port: 3000 + onOpen: open-preview +- port: 3001 + onOpen: ignore +tasks: +- init: cargo build + command: > + cd ./book-example && + ../target/debug/mdbook serve \ + --hostname 0.0.0.0 \ + --websocket-url $(echo $GITPOD_WORKSPACE_URL | sed 's/https:\/\//wss:\/\/3001-/g') diff --git a/README.md b/README.md index 97633599..c29341a1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ + @@ -79,8 +80,11 @@ There are multiple ways to install mdBook. 4. **For Contributions** - If you want to contribute to mdBook you will have to clone the repository on - your local machine: + If you want to contribute to mdBook you have two options: + + ***Local Development*** + + Clone the repository on your local machine: ``` git clone https://github.com/rust-lang-nursery/mdBook.git @@ -95,6 +99,11 @@ There are multiple ways to install mdBook. The resulting binary can be found in `mdBook/target/debug/` under the name `mdBook` or `mdBook.exe`. + ***Online Development*** + + You can start a readily configured online workspace using Gitpod. + + [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io#https://github.com/rust-lang-nursery/mdBook) ## Usage diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 3c8c53dc..ee06e3e3 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -58,6 +58,13 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { .empty_values(false) .help("Port to use for WebSockets livereload connections"), ) + .arg( + Arg::with_name("websocket-url") + .long("websocket-url") + .takes_value(true) + .empty_values(false) + .help("URL to use for WebSockets livereload connections (Defaults to 'ws://{websocket-hostname}:{websocket-port})')"), + ) .arg_from_usage("-o, --open 'Opens the book server in a web browser'") } @@ -67,17 +74,21 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let mut book = MDBook::load(&book_dir)?; let port = args.value_of("port").unwrap(); - let ws_port = args.value_of("websocket-port").unwrap(); let hostname = args.value_of("hostname").unwrap(); - let public_address = args.value_of("websocket-hostname").unwrap_or(hostname); + let ws_port = args.value_of("websocket-port").unwrap(); + let ws_hostname = args.value_of("websocket-hostname").unwrap_or(hostname); + let ws_url = match args.value_of("websocket-url") { + Some(url) => String::from(url), + None => format!("ws://{}:{}", ws_hostname, ws_port) + }; + let ws_url = &ws_url[..]; let open_browser = args.is_present("open"); let address = format!("{}:{}", hostname, port); let ws_address = format!("{}:{}", hostname, ws_port); - let livereload_url = format!("ws://{}:{}", public_address, ws_port); book.config - .set("output.html.livereload-url", &livereload_url)?; + .set("output.html.livereload-url", &ws_url)?; if let Some(dest_dir) = args.value_of("dest-dir") { book.config.build.build_dir = dest_dir.into(); @@ -117,7 +128,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let result = MDBook::load(&book_dir) .and_then(|mut b| { b.config - .set("output.html.livereload-url", &livereload_url)?; + .set("output.html.livereload-url", &ws_url)?; Ok(b) }) .and_then(|b| b.build());