Skip to content

Commit

Permalink
Construct book build path outside process_book
Browse files Browse the repository at this point in the history
  • Loading branch information
Coi-l committed Mar 30, 2024
1 parent fc2bcf3 commit cc679ca
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/cmd/shelf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env::current_dir;
use std::fs::File;
use std::io::Read;
use std::io::Write;
Expand Down Expand Up @@ -69,18 +68,16 @@ fn update_index(
Ok(())
}

fn process_book(path: &str, shelf_url: &PathBuf) -> Result<BookContext> {
fn process_book(path: &str, books_dir: &PathBuf, shelf_url: &PathBuf) -> Result<BookContext> {
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()?;
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit cc679ca

Please sign in to comment.