@@ -16,6 +16,7 @@ const REPOS_DIR: &str = "repositories";
16
16
const INDEX_MD_FILE : & str = "index.md" ;
17
17
const INDEX_HTML_FILE : & str = "index.html" ;
18
18
const BOOKS_DIR : & str = "books" ;
19
+ const BOOKSHELF_DIR : & str = "bookshelf" ;
19
20
20
21
pub fn make_subcommand ( ) -> Command {
21
22
Command :: new ( "shelf" ) . about ( "Build a bookshelf from shelf.toml file" )
@@ -35,6 +36,7 @@ fn process_book(
35
36
// Build book
36
37
let title = book. config . book . title . clone ( ) . unwrap ( ) ;
37
38
let mut path = current_dir ( ) ?;
39
+ path. push ( BOOKSHELF_DIR ) ;
38
40
path. push ( BOOKS_DIR ) ;
39
41
path. push ( title) ;
40
42
book. config . build . build_dir = path;
@@ -76,15 +78,25 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
76
78
let mut file = File :: open ( "shelf.toml" ) ?;
77
79
let mut contents = String :: new ( ) ;
78
80
file. read_to_string ( & mut contents) ?;
79
- let shelf : Shelf = toml:: from_str ( & contents) ?;
81
+ let shelf_config : Shelf = toml:: from_str ( & contents) ?;
80
82
81
- let _ = std:: fs:: remove_dir_all ( SHELF_DIR ) ;
83
+ let _ = std:: fs:: remove_dir_all ( BOOKSHELF_DIR ) ;
82
84
let _ = std:: fs:: remove_dir_all ( REPOS_DIR ) ;
83
- let shelf_book = MDBook :: init ( SHELF_DIR ) . create_gitignore ( false ) . build ( ) ?;
85
+ let shelf_book_dir = format ! ( "{BOOKSHELF_DIR}/{SHELF_DIR}" ) ;
86
+ let shelf_book = MDBook :: init ( & shelf_book_dir)
87
+ . create_gitignore ( false )
88
+ . build ( ) ?;
84
89
let shelf_source = shelf_book. source_dir ( ) ;
85
90
let shelf_build_dir = shelf_book. config . build . build_dir . to_str ( ) . unwrap_or ( "book" ) ;
91
+ let shelf_url_prefix = if let Some ( prefix) = shelf_config. root_url_prefix {
92
+ let mut full_prefix = "/" . to_owned ( ) ;
93
+ full_prefix. push_str ( & prefix) ;
94
+ full_prefix
95
+ } else {
96
+ "" . to_owned ( )
97
+ } ;
86
98
let shelf_url = PathBuf :: from ( format ! (
87
- "../../{SHELF_DIR }/{shelf_build_dir}/{INDEX_HTML_FILE}"
99
+ "{shelf_url_prefix}/{shelf_book_dir }/{shelf_build_dir}/{INDEX_HTML_FILE}"
88
100
) ) ;
89
101
90
102
let mut index_file_name = shelf_book. source_dir ( ) ;
@@ -99,7 +111,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
99
111
writeln ! ( summary, "# Summary" ) ?;
100
112
writeln ! ( summary, "- [Index](./{INDEX_MD_FILE})" ) ?;
101
113
102
- for sb in & shelf . book {
114
+ for sb in & shelf_config . book {
103
115
if let Some ( url) = & sb. git_url {
104
116
println ! ( "{:?}" , sb) ;
105
117
let path = sb. path . clone ( ) . unwrap_or ( "root" . to_owned ( ) ) ;
@@ -169,7 +181,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
169
181
}
170
182
}
171
183
172
- let shelf = MDBook :: load ( "shelf" ) ?;
184
+ let shelf = MDBook :: load ( & shelf_book_dir ) ?;
173
185
shelf. build ( ) ?;
174
186
175
187
Ok ( ( ) )
0 commit comments