From 1083d1822dca01275d25e8420272d576ffafad3f Mon Sep 17 00:00:00 2001 From: Jesse Stricker Date: Mon, 22 Feb 2016 16:59:53 +0100 Subject: [PATCH 1/3] Add default favicon.png --- src/theme/favicon.png | Bin 0 -> 5679 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/theme/favicon.png diff --git a/src/theme/favicon.png b/src/theme/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..a5b1aa16c4dcb6c872cb5af799bfc9b5552c7b9e GIT binary patch literal 5679 zcmaKwcQhN&+sD<65fVyMrKCtvVz>54LX99&YDJBr_J}>&8nH)>5R@84MNz9ITCG*P zX0<44?^;#6_4>Wr#V&J8m1AkprJ&CCG60hiIs8wiCL z#DZiT`@6@!`1|?!W$KnZXnX^2+=d_hxD?}hboJ~h?Z3p^&%c2CYBPHWm3|C7?4S)S z<=8>rwHV}maohw}kN+bB?OodAZp_b^;z<(fft-=472pgWXh~>V9TV@+f@jN9eBDb8 z7XHu2>hath5j`z|b;Ad2K;UB)cLZ_o3=_`cn$3dBvrK8=_c@&)Co@h@Pv4py{4-VG zZ5jW&6>DrRtr<|%Fe?ncBXZ&-%N-M8DAk#!lh2}pj>hTyRLw-Y@j^l@;vBq_lsS75 z)qdTT8D@D}Dii_QlsRP&RSJqu0GI`03S)>yR&aVKQRp}j!xeZZtz;w73{iCK&bLCE z+>)g!H+&K+40SZ~GUg@L=NTM^3f#ws*h)fa+1^TLfkKX0cOC&h^&$#734jCMlkosy zmd-3tD>m+NOhmzi8_WaR-6=gM$YT}*bmNV`pA@5OxA3<=Q1`U?J!Hn_;zv{eIRg zOFf{KJb(ijx*?h43sdXmvg??24dL#E3BQSwKa7K16Vfe7C{X5}#}S=h395Gr8tI#4 zrrXi%UzXQ+xVq%dG=XgJJ;R{?RK?)mMzlW`d>wIS2I$CY#jkO8)qKV{zRyiyxA_TK zpQ2lmzVdp}WSg;LaU?Luyp_y8A4v1Y8KL-9=|}S1(8e%kW&{6^S&9Y3fBc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_jpSA!nF{`!bL7B zr7;#NX8gSM&>Zr)hSeg3HAf!6p&eUTSXiFB#^NfZxClok&YLkTsW3RqM=;_EDP^Mn zw&J(8wt#LTOt!oj(X~wlr$x|XVMKSXa(etHtMC^O&3p*~E1vL&U3WiZNjbxB zPRi5++1NZ6OC7~7d5P@WWxsrV7d3U`(#+}c>hrXlw8?VFLCJo70{9YyYBIY7$=e4n z_FTPA74839$pPh*_!lO@h^YmMhrLW(-co+j%%Umn^vlz|BFd@o!JEUfej6D`tYh88 z!xOp88&kL_omR|hhQy%VV570%z31uE7nsb&=9lx0f~QVs}&QZli(7C+4WInF(c~1G?Ay}@=Js6#Ta&S*M8tzG+=nyvS4C!u0HG7 zKX=aXY38nuJz&^FN?mu3@F1#E%R_S9N%lmfUjlL$z@X6N1%x{Wxw=n$=IRLiRFDx) zC-B0x)S*v13dEu{-17fX(EmoH?UHAPVV9_q-f;^!OLHAu5MU}DO#@UF!Y1N>0Q+#1 A;{X5v literal 0 HcmV?d00001 From f508db61130e12015ec7358179b29179ca0a11c0 Mon Sep 17 00:00:00 2001 From: Jesse Stricker Date: Mon, 22 Feb 2016 17:17:07 +0100 Subject: [PATCH 2/3] Add favicon support to theme --- src/renderer/html_handlebars/hbs_renderer.rs | 7 +++++++ src/theme/index.hbs | 2 ++ src/theme/mod.rs | 9 +++++++++ 3 files changed, 18 insertions(+) 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/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(); From 88fabd76f0533afa757729fd8ddc42a1fcfa18c5 Mon Sep 17 00:00:00 2001 From: Jesse Stricker Date: Mon, 22 Feb 2016 17:20:54 +0100 Subject: [PATCH 3/3] Copy favicon on 'init --theme' --- src/book/mdbook.rs | 4 ++++ 1 file changed, 4 insertions(+) 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));