Skip to content

Commit

Permalink
Merge pull request rust-lang#1228 from ehuss/fix-dest-dir
Browse files Browse the repository at this point in the history
Fix dest-dir command-line flag.
  • Loading branch information
ehuss committed Jun 23, 2020
2 parents 199322c + 54128e9 commit 36b1edd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
31 changes: 15 additions & 16 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
let address = format!("{}:{}", hostname, port);

let livereload_url = format!("ws://{}/{}", address, LIVE_RELOAD_ENDPOINT);
book.config
.set("output.html.livereload-url", &livereload_url)?;

if let Some(dest_dir) = args.value_of("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
// Override site-url for local serving of the 404 file
book.config.set("output.html.site-url", "/")?;

let update_config = |book: &mut MDBook| {
book.config
.set("output.html.livereload-url", &livereload_url)
.expect("livereload-url update failed");
if let Some(dest_dir) = args.value_of("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
// Override site-url for local serving of the 404 file
book.config.set("output.html.site-url", "/").unwrap();
};
update_config(&mut book);
book.build()?;

let sockaddr: SocketAddr = address
Expand Down Expand Up @@ -108,13 +110,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
info!("Building book...");

// FIXME: This area is really ugly because we need to re-set livereload :(
let result = MDBook::load(&book_dir)
.and_then(|mut b| {
b.config
.set("output.html.livereload-url", &livereload_url)?;
Ok(b)
})
.and_then(|b| b.build());
let result = MDBook::load(&book_dir).and_then(|mut b| {
update_config(&mut b);
b.build()
});

if let Err(e) = result {
error!("Unable to load the book");
Expand Down
14 changes: 12 additions & 2 deletions src/cmd/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
// Watch command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let book_dir = get_book_dir(args);
let book = MDBook::load(&book_dir)?;
let mut book = MDBook::load(&book_dir)?;

let update_config = |book: &mut MDBook| {
if let Some(dest_dir) = args.value_of("dest-dir") {
book.config.build.build_dir = dest_dir.into();
}
};
update_config(&mut book);

if args.is_present("open") {
book.build()?;
Expand All @@ -37,7 +44,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {

trigger_on_change(&book, |paths, book_dir| {
info!("Files changed: {:?}\nBuilding book...\n", paths);
let result = MDBook::load(&book_dir).and_then(|b| b.build());
let result = MDBook::load(&book_dir).and_then(|mut b| {
update_config(&mut b);
b.build()
});

if let Err(e) = result {
error!("Unable to build the book");
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ impl HtmlHandlebars {
data_404.insert("content".to_owned(), json!(html_content_404));
let rendered = handlebars.render("index", &data_404)?;

let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition);
let rendered =
self.post_process(rendered, &html_config.playground, ctx.config.rust.edition);
let output_file = get_404_output_file(&html_config.input_404);
utils::fs::write_file(&destination, output_file, rendered.as_bytes())?;
debug!("Creating 404.html ✓");
Expand Down

0 comments on commit 36b1edd

Please sign in to comment.