Skip to content

Commit

Permalink
Better shelf_url backreference setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Coi-l committed Mar 26, 2024
1 parent c0b83d0 commit d2ca6e3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/cmd/shelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit d2ca6e3

Please sign in to comment.