diff --git a/src/cmd/shelf.rs b/src/cmd/shelf.rs index d9a785a878..bfaeac9f43 100644 --- a/src/cmd/shelf.rs +++ b/src/cmd/shelf.rs @@ -1,4 +1,3 @@ -use std::env::current_dir; use std::fs::File; use std::io::Read; use std::io::Write; @@ -69,18 +68,16 @@ fn update_index( Ok(()) } -fn process_book(path: &str, shelf_url: &PathBuf) -> Result { +fn process_book(path: &str, books_dir: &PathBuf, shelf_url: &PathBuf) -> Result { let book_dir = path.try_resolve()?; let book_dir = std::fs::canonicalize(book_dir)?; let mut book = MDBook::load(book_dir)?; // Build book let title = book.config.book.title.clone().unwrap(); - let mut path = current_dir()?; - path.push(BOOKSHELF_DIR); - path.push(BOOKS_DIR); - path.push(title); - book.config.build.build_dir = path; + let mut build_path = books_dir.to_owned(); + build_path.push(title); + book.config.build.build_dir = build_path; // Create back reference to bookshelf book.config.book.shelf_url = Some(shelf_url.to_owned()); book.build()?; @@ -131,6 +128,10 @@ pub fn execute(_args: &ArgMatches) -> Result<()> { writeln!(summary_file, "# Summary")?; writeln!(summary_file, "- [Index](./{INDEX_MD_FILE})")?; + let mut books_build_dir = std::env::current_dir()?; + books_build_dir.push(BOOKSHELF_DIR); + books_build_dir.push(BOOKS_DIR); + for sb in &shelf_config.books { let book_path = if let Some(url) = &sb.git_url { prepare_git(sb, url) @@ -142,7 +143,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> { }; if let Some(path) = book_path { - let update_context = process_book(&path, &shelf_url)?; + let update_context = process_book(&path, &books_build_dir, &shelf_url)?; let _ = update_index( &mut index_file, &mut summary_file,