Skip to content

Commit 2bdca9e

Browse files
Fixed mdbook build overwriting your book with the mdbook init stuff
1 parent 1bd26fb commit 2bdca9e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/bin/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
1717
// Build command implementation
1818
pub fn execute(args: &ArgMatches) -> Result<()> {
1919
let book_dir = get_book_dir(args);
20-
let book = MDBook::new(&book_dir).read_config()?;
20+
let book = MDBook::new(&book_dir);
2121

2222
let mut book = match args.value_of("dest-dir") {
2323
Some(dest_dir) => book.with_destination(dest_dir),
@@ -30,6 +30,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
3030
book = book.with_curly_quotes(true);
3131
}
3232

33+
book = book.read_config()?;
3334
book.build()?;
3435

3536
if args.is_present("open") {

src/book/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl MDBook {
8383
renderer: Box::new(HtmlHandlebars::new()),
8484

8585
livereload: None,
86-
create_missing: true,
86+
create_missing: false,
8787
}
8888
}
8989

@@ -175,15 +175,18 @@ impl MDBook {
175175
let src = self.config.get_source();
176176
let summary = src.join("SUMMARY.md");
177177

178-
if summary.exists() && self.create_missing {
178+
if summary.exists() {
179+
if self.create_missing {
179180
// As a special case, if we run "mdbook init" on a book which
180181
// already has a summary we'll read that summary and create
181182
// stubs for any files which don't already exist (@azerupi likes
182183
// having access to this shortcut).
183184
return create_files_from_summary(&src, &summary);
185+
} else {
186+
return Ok(());
187+
}
184188
}
185189

186-
// We need to create the summary file
187190
debug!("[*]: Creating SUMMARY.md");
188191
let mut f = File::create(&summary)?;
189192
writeln!(f, "{}", STUB_SUMMARY_CONTENTS)?;

0 commit comments

Comments
 (0)