Skip to content

Added gitpod support #836

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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')
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<td colspan="2">
<a href="https://crates.io/crates/mdbook"><img src="https://img.shields.io/crates/v/mdbook.svg"></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/rust-lang-nursery/mdBook.svg"></a>
<a href="https://gitpod.io/from-referrer/"><img src="https://img.shields.io/badge/setup-automated-blue?logo=gitpod"></a>
</td>
</tr>
</table>
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 16 additions & 5 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}

Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand Down