1
- use std:: env:: current_dir;
2
1
use std:: fs:: File ;
3
2
use std:: io:: Read ;
4
3
use std:: io:: Write ;
@@ -69,18 +68,16 @@ fn update_index(
69
68
Ok ( ( ) )
70
69
}
71
70
72
- fn process_book ( path : & str , shelf_url : & PathBuf ) -> Result < BookContext > {
71
+ fn process_book ( path : & str , books_dir : & PathBuf , shelf_url : & PathBuf ) -> Result < BookContext > {
73
72
let book_dir = path. try_resolve ( ) ?;
74
73
let book_dir = std:: fs:: canonicalize ( book_dir) ?;
75
74
let mut book = MDBook :: load ( book_dir) ?;
76
75
77
76
// Build book
78
77
let title = book. config . book . title . clone ( ) . unwrap ( ) ;
79
- let mut path = current_dir ( ) ?;
80
- path. push ( BOOKSHELF_DIR ) ;
81
- path. push ( BOOKS_DIR ) ;
82
- path. push ( title) ;
83
- book. config . build . build_dir = path;
78
+ let mut build_path = books_dir. to_owned ( ) ;
79
+ build_path. push ( title) ;
80
+ book. config . build . build_dir = build_path;
84
81
// Create back reference to bookshelf
85
82
book. config . book . shelf_url = Some ( shelf_url. to_owned ( ) ) ;
86
83
book. build ( ) ?;
@@ -131,6 +128,10 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
131
128
writeln ! ( summary_file, "# Summary" ) ?;
132
129
writeln ! ( summary_file, "- [Index](./{INDEX_MD_FILE})" ) ?;
133
130
131
+ let mut books_build_dir = std:: env:: current_dir ( ) ?;
132
+ books_build_dir. push ( BOOKSHELF_DIR ) ;
133
+ books_build_dir. push ( BOOKS_DIR ) ;
134
+
134
135
for sb in & shelf_config. books {
135
136
let book_path = if let Some ( url) = & sb. git_url {
136
137
prepare_git ( sb, url)
@@ -142,7 +143,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
142
143
} ;
143
144
144
145
if let Some ( path) = book_path {
145
- let update_context = process_book ( & path, & shelf_url) ?;
146
+ let update_context = process_book ( & path, & books_build_dir , & shelf_url) ?;
146
147
let _ = update_index (
147
148
& mut index_file,
148
149
& mut summary_file,
0 commit comments