diff --git a/src/cmd/shelf.rs b/src/cmd/shelf.rs index 919b6f95be..287b221071 100644 --- a/src/cmd/shelf.rs +++ b/src/cmd/shelf.rs @@ -26,18 +26,20 @@ fn process_book( index_file: &mut File, summary: &mut File, shelf_source: &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 mut path = current_dir()?; let title = book.config.book.title.clone().unwrap(); + let mut path = current_dir()?; path.push(BOOKS_DIR); path.push(title); book.config.build.build_dir = path; - book.config.book.shelf_url = Some(PathBuf::from(r"../../shelf/book/index.html")); + // Create back reference to bookshelf + book.config.book.shelf_url = Some(shelf_url.to_path_buf()); book.build()?; // Create post in index file @@ -77,6 +79,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> { let _ = std::fs::remove_dir_all(REPOS_DIR); let shelf_book = MDBook::init(SHELF_DIR).create_gitignore(false).build()?; let shelf_source = shelf_book.source_dir(); + let shelf_url = PathBuf::from(format!("../../{SHELF_DIR}/book/{INDEX_HTML_FILE}")); let mut index_file_name = shelf_book.source_dir(); index_file_name.push(INDEX_MD_FILE); @@ -145,9 +148,16 @@ pub fn execute(_args: &ArgMatches) -> Result<()> { &mut index_file, &mut summary, &shelf_source, + &shelf_url, )? } else if let Some(path) = &sb.path { - process_book(path, &mut index_file, &mut summary, &shelf_source)? + process_book( + path, + &mut index_file, + &mut summary, + &shelf_source, + &shelf_url, + )? } else { warn!("Neither path or git specified. Invalid book"); }