diff --git a/book-example/book/README.html b/book-example/book/README.html index 4c56ee9a..222d65f9 100644 --- a/book-example/book/README.html +++ b/book-example/book/README.html @@ -2,7 +2,7 @@ - + mdBook Documentation @@ -22,7 +22,7 @@
diff --git a/book-example/book/book.css b/book-example/book/book.css index ed958c2d..ced1eeeb 100644 --- a/book-example/book/book.css +++ b/book-example/book/book.css @@ -109,11 +109,13 @@ html, body { } .menu-bar { + position: relative; height: 50px; color: #CCC; } .menu-bar i { + line-height: 50px; -webkit-transition: color 0.5s; /* Safari */ -o-transition: color 0.5s; /* Opera */ -moz-transition: color 0.5s; /* Mozilla Firefox */ @@ -125,6 +127,32 @@ html, body { color: #333; } +.menu-title { + color: #7E7E7E; + display: inline-block; + font-weight: 200; + font-size: 20px; + line-height: 50px; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + text-align: center; + margin: 0; + + opacity: 0; + -webkit-transition: opacity 0.5s ease-in-out; /* Safari */ + -o-transition: opacity 0.5s ease-in-out; /* Opera */ + -moz-transition: opacity 0.5s ease-in-out; /* Mozilla Firefox */ + transition: opacity 0.5s ease-in-out; +} + +.menu-title:hover { + color: #7E7E7E; + opacity: 1; +} + pre { padding: 16px; overflow: auto; diff --git a/book-example/book/cli/build.html b/book-example/book/cli/build.html index d672d319..7b714c45 100644 --- a/book-example/book/cli/build.html +++ b/book-example/book/cli/build.html @@ -2,7 +2,7 @@ - + mdBook Documentation @@ -22,7 +22,7 @@
diff --git a/book-example/book/cli/cli-tool.html b/book-example/book/cli/cli-tool.html index 95b588f8..4cdc0e95 100644 --- a/book-example/book/cli/cli-tool.html +++ b/book-example/book/cli/cli-tool.html @@ -2,7 +2,7 @@ - + mdBook Documentation @@ -22,7 +22,7 @@
diff --git a/book-example/book/cli/init.html b/book-example/book/cli/init.html index bd9e44cc..6eac333e 100644 --- a/book-example/book/cli/init.html +++ b/book-example/book/cli/init.html @@ -2,7 +2,7 @@ - + mdBook Documentation @@ -22,7 +22,7 @@
diff --git a/book-example/book/index.html b/book-example/book/index.html index 4c56ee9a..222d65f9 100644 --- a/book-example/book/index.html +++ b/book-example/book/index.html @@ -2,7 +2,7 @@ - + mdBook Documentation @@ -22,7 +22,7 @@
diff --git a/book-example/src/book.json b/book-example/src/book.json new file mode 100644 index 00000000..40f533d9 --- /dev/null +++ b/book-example/src/book.json @@ -0,0 +1,3 @@ +{ + "title": "mdBook Documentation" +} diff --git a/src/book/bookconfig.rs b/src/book/bookconfig.rs index 2e958cb0..f1020345 100644 --- a/src/book/bookconfig.rs +++ b/src/book/bookconfig.rs @@ -1,3 +1,7 @@ +extern crate rustc_serialize; +use self::rustc_serialize::json::Json; +use std::fs::File; +use std::io::Read; use std::path::{Path, PathBuf}; #[derive(Debug, Clone)] @@ -23,6 +27,26 @@ impl BookConfig { } } + pub fn read_config(&mut self) -> &mut Self { + + // If the file does not exist, return early + let mut config_file = match File::open(self.src.join("book.json")) { + Ok(f) => f, + Err(_) => return self, + }; + + let mut data = String::new(); + config_file.read_to_string(&mut data).unwrap(); + + // Convert to JSON + let config = Json::from_str(&data).unwrap(); + + // Extract data + if let Some(a) = config.find_path(&["title"]) { self.title = a.to_string().replace("\"", "") } + + self + } + pub fn dest(&self) -> &Path { &self.dest } @@ -40,4 +64,5 @@ impl BookConfig { self.src = src.to_owned(); self } + } diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs index 4a7b707e..6fa45e2b 100644 --- a/src/book/mdbook.rs +++ b/src/book/mdbook.rs @@ -111,6 +111,11 @@ impl MDBook { // Builder functions + pub fn read_config(mut self) -> Self { + self.config.read_config(); + self + } + pub fn set_dest(mut self, dest: &Path) -> Self { self.config.set_dest(dest); self diff --git a/src/main.rs b/src/main.rs index 4e9d878b..cd508173 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ fn init(args: &ArgMatches) -> Result<(), Box> { fn build(args: &ArgMatches) -> Result<(), Box> { let book_dir = get_book_dir(args); - let mut book = MDBook::new(&book_dir); + let mut book = MDBook::new(&book_dir).read_config(); book.build() } diff --git a/src/theme/book.css b/src/theme/book.css index ed958c2d..ced1eeeb 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -109,11 +109,13 @@ html, body { } .menu-bar { + position: relative; height: 50px; color: #CCC; } .menu-bar i { + line-height: 50px; -webkit-transition: color 0.5s; /* Safari */ -o-transition: color 0.5s; /* Opera */ -moz-transition: color 0.5s; /* Mozilla Firefox */ @@ -125,6 +127,32 @@ html, body { color: #333; } +.menu-title { + color: #7E7E7E; + display: inline-block; + font-weight: 200; + font-size: 20px; + line-height: 50px; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + text-align: center; + margin: 0; + + opacity: 0; + -webkit-transition: opacity 0.5s ease-in-out; /* Safari */ + -o-transition: opacity 0.5s ease-in-out; /* Opera */ + -moz-transition: opacity 0.5s ease-in-out; /* Mozilla Firefox */ + transition: opacity 0.5s ease-in-out; +} + +.menu-title:hover { + color: #7E7E7E; + opacity: 1; +} + pre { padding: 16px; overflow: auto;