Skip to content

Commit c1ed6ee

Browse files
authored
Merge pull request #1228 from ehuss/fix-dest-dir
Fix dest-dir command-line flag.
2 parents 9268884 + f59cfe7 commit c1ed6ee

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/cmd/serve.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
6363
let address = format!("{}:{}", hostname, port);
6464

6565
let livereload_url = format!("ws://{}/{}", address, LIVE_RELOAD_ENDPOINT);
66-
book.config
67-
.set("output.html.livereload-url", &livereload_url)?;
68-
69-
if let Some(dest_dir) = args.value_of("dest-dir") {
70-
book.config.build.build_dir = dest_dir.into();
71-
}
72-
// Override site-url for local serving of the 404 file
73-
book.config.set("output.html.site-url", "/")?;
74-
66+
let update_config = |book: &mut MDBook| {
67+
book.config
68+
.set("output.html.livereload-url", &livereload_url)
69+
.expect("livereload-url update failed");
70+
if let Some(dest_dir) = args.value_of("dest-dir") {
71+
book.config.build.build_dir = dest_dir.into();
72+
}
73+
// Override site-url for local serving of the 404 file
74+
book.config.set("output.html.site-url", "/").unwrap();
75+
};
76+
update_config(&mut book);
7577
book.build()?;
7678

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

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

119118
if let Err(e) = result {
120119
error!("Unable to load the book");

src/cmd/watch.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
2828
// Watch command implementation
2929
pub fn execute(args: &ArgMatches) -> Result<()> {
3030
let book_dir = get_book_dir(args);
31-
let book = MDBook::load(&book_dir)?;
31+
let mut book = MDBook::load(&book_dir)?;
32+
33+
let update_config = |book: &mut MDBook| {
34+
if let Some(dest_dir) = args.value_of("dest-dir") {
35+
book.config.build.build_dir = dest_dir.into();
36+
}
37+
};
38+
update_config(&mut book);
3239

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

3845
trigger_on_change(&book, |paths, book_dir| {
3946
info!("Files changed: {:?}\nBuilding book...\n", paths);
40-
let result = MDBook::load(&book_dir).and_then(|b| b.build());
47+
let result = MDBook::load(&book_dir).and_then(|mut b| {
48+
update_config(&mut b);
49+
b.build()
50+
});
4151

4252
if let Err(e) = result {
4353
error!("Unable to build the book");

src/renderer/html_handlebars/hbs_renderer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ impl HtmlHandlebars {
151151
data_404.insert("content".to_owned(), json!(html_content_404));
152152
let rendered = handlebars.render("index", &data_404)?;
153153

154-
let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition);
154+
let rendered =
155+
self.post_process(rendered, &html_config.playground, ctx.config.rust.edition);
155156
let output_file = get_404_output_file(&html_config.input_404);
156157
utils::fs::write_file(&destination, output_file, rendered.as_bytes())?;
157158
debug!("Creating 404.html ✓");

0 commit comments

Comments
 (0)