@@ -16,6 +16,7 @@ const REPOS_DIR: &str = "repositories";
1616const INDEX_MD_FILE : & str = "index.md" ;
1717const INDEX_HTML_FILE : & str = "index.html" ;
1818const BOOKS_DIR : & str = "books" ;
19+ const BOOKSHELF_DIR : & str = "bookshelf" ;
1920
2021pub fn make_subcommand ( ) -> Command {
2122 Command :: new ( "shelf" ) . about ( "Build a bookshelf from shelf.toml file" )
@@ -35,6 +36,7 @@ fn process_book(
3536 // Build book
3637 let title = book. config . book . title . clone ( ) . unwrap ( ) ;
3738 let mut path = current_dir ( ) ?;
39+ path. push ( BOOKSHELF_DIR ) ;
3840 path. push ( BOOKS_DIR ) ;
3941 path. push ( title) ;
4042 book. config . build . build_dir = path;
@@ -76,15 +78,25 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
7678 let mut file = File :: open ( "shelf.toml" ) ?;
7779 let mut contents = String :: new ( ) ;
7880 file. read_to_string ( & mut contents) ?;
79- let shelf : Shelf = toml:: from_str ( & contents) ?;
81+ let shelf_config : Shelf = toml:: from_str ( & contents) ?;
8082
81- let _ = std:: fs:: remove_dir_all ( SHELF_DIR ) ;
83+ let _ = std:: fs:: remove_dir_all ( BOOKSHELF_DIR ) ;
8284 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 ( ) ?;
8489 let shelf_source = shelf_book. source_dir ( ) ;
8590 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+ } ;
8698 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}"
88100 ) ) ;
89101
90102 let mut index_file_name = shelf_book. source_dir ( ) ;
@@ -99,7 +111,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
99111 writeln ! ( summary, "# Summary" ) ?;
100112 writeln ! ( summary, "- [Index](./{INDEX_MD_FILE})" ) ?;
101113
102- for sb in & shelf . book {
114+ for sb in & shelf_config . book {
103115 if let Some ( url) = & sb. git_url {
104116 println ! ( "{:?}" , sb) ;
105117 let path = sb. path . clone ( ) . unwrap_or ( "root" . to_owned ( ) ) ;
@@ -169,7 +181,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
169181 }
170182 }
171183
172- let shelf = MDBook :: load ( "shelf" ) ?;
184+ let shelf = MDBook :: load ( & shelf_book_dir ) ?;
173185 shelf. build ( ) ?;
174186
175187 Ok ( ( ) )
0 commit comments