diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs index 2209bc36..521606d3 100644 --- a/src/book/mdbook.rs +++ b/src/book/mdbook.rs @@ -198,6 +198,10 @@ impl MDBook { let mut css = try!(File::create(&theme_dir.join("book.css"))); try!(css.write_all(theme::CSS)); + // favicon.png + let mut favicon = try!(File::create(&theme_dir.join("favicon.png"))); + try!(favicon.write_all(theme::FAVICON)); + // book.js let mut js = try!(File::create(&theme_dir.join("book.js"))); try!(js.write_all(theme::JS)); diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 68753ceb..613972fe 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -170,6 +170,12 @@ impl Renderer for HtmlHandlebars { }; try!(css_file.write_all(&theme.css)); + // Favicon + let mut favicon_file = if let Ok(f) = File::create(book.get_dest().join("favicon.png")) { f } else { + return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create favicon.png"))) + }; + try!(favicon_file.write_all(&theme.favicon)); + // JQuery local fallback let mut jquery = if let Ok(f) = File::create(book.get_dest().join("jquery.js")) { f } else { return Err(Box::new(io::Error::new(io::ErrorKind::Other, "Could not create jquery.js"))) @@ -235,6 +241,7 @@ fn make_data(book: &MDBook) -> Result, Box> { let mut data = BTreeMap::new(); data.insert("language".to_owned(), "en".to_json()); data.insert("title".to_owned(), book.get_title().to_json()); + data.insert("favicon".to_owned(), "favicon.png".to_json()); let mut chapters = vec![]; diff --git a/src/theme/favicon.png b/src/theme/favicon.png new file mode 100644 index 00000000..a5b1aa16 Binary files /dev/null and b/src/theme/favicon.png differ diff --git a/src/theme/index.hbs b/src/theme/index.hbs index e4340673..98c959cf 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -12,6 +12,8 @@ + + diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 5fca68fd..e02aca3c 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -5,6 +5,7 @@ use std::io::Read; pub static INDEX: &'static [u8] = include_bytes!("index.hbs"); pub static CSS: &'static [u8] = include_bytes!("book.css"); +pub static FAVICON: &'static [u8] = include_bytes!("favicon.png"); pub static JS: &'static [u8] = include_bytes!("book.js"); pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js"); pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.css"); @@ -27,6 +28,7 @@ pub static FONT_AWESOME_OTF: &'static [u8] = include_bytes!("_FontAwesome/fonts/ pub struct Theme { pub index: Vec, pub css: Vec, + pub favicon: Vec, pub js: Vec, pub highlight_css: Vec, pub tomorrow_night_css: Vec, @@ -41,6 +43,7 @@ impl Theme { let mut theme = Theme { index: INDEX.to_owned(), css: CSS.to_owned(), + favicon: FAVICON.to_owned(), js: JS.to_owned(), highlight_css: HIGHLIGHT_CSS.to_owned(), tomorrow_night_css: TOMORROW_NIGHT_CSS.to_owned(), @@ -79,6 +82,12 @@ impl Theme { let _ = f.read_to_end(&mut theme.css); } + // favicon.png + if let Ok(mut f) = File::open(&src.join("favicon.png")) { + theme.favicon.clear(); + let _ = f.read_to_end(&mut theme.favicon); + } + // highlight.js if let Ok(mut f) = File::open(&src.join("highlight.js")) { theme.highlight_js.clear();