Merge pull request #109 from jessestricker/feature-favicon
Add theme support for favicon
This commit is contained in:
commit
9f17be2c32
|
@ -198,6 +198,10 @@ impl MDBook {
|
||||||
let mut css = try!(File::create(&theme_dir.join("book.css")));
|
let mut css = try!(File::create(&theme_dir.join("book.css")));
|
||||||
try!(css.write_all(theme::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
|
// book.js
|
||||||
let mut js = try!(File::create(&theme_dir.join("book.js")));
|
let mut js = try!(File::create(&theme_dir.join("book.js")));
|
||||||
try!(js.write_all(theme::JS));
|
try!(js.write_all(theme::JS));
|
||||||
|
|
|
@ -170,6 +170,12 @@ impl Renderer for HtmlHandlebars {
|
||||||
};
|
};
|
||||||
try!(css_file.write_all(&theme.css));
|
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
|
// JQuery local fallback
|
||||||
let mut jquery = if let Ok(f) = File::create(book.get_dest().join("jquery.js")) { f } else {
|
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")))
|
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<BTreeMap<String,Json>, Box<Error>> {
|
||||||
let mut data = BTreeMap::new();
|
let mut data = BTreeMap::new();
|
||||||
data.insert("language".to_owned(), "en".to_json());
|
data.insert("language".to_owned(), "en".to_json());
|
||||||
data.insert("title".to_owned(), book.get_title().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![];
|
let mut chapters = vec![];
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
|
@ -12,6 +12,8 @@
|
||||||
<link rel="stylesheet" href="book.css">
|
<link rel="stylesheet" href="book.css">
|
||||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
|
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
|
||||||
|
|
||||||
|
<link rel="shortcut icon" href="{{ favicon }}">
|
||||||
|
|
||||||
<!-- Font Awesome -->
|
<!-- Font Awesome -->
|
||||||
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::io::Read;
|
||||||
|
|
||||||
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
|
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
|
||||||
pub static CSS: &'static [u8] = include_bytes!("book.css");
|
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 JS: &'static [u8] = include_bytes!("book.js");
|
||||||
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
|
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
|
||||||
pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.css");
|
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 struct Theme {
|
||||||
pub index: Vec<u8>,
|
pub index: Vec<u8>,
|
||||||
pub css: Vec<u8>,
|
pub css: Vec<u8>,
|
||||||
|
pub favicon: Vec<u8>,
|
||||||
pub js: Vec<u8>,
|
pub js: Vec<u8>,
|
||||||
pub highlight_css: Vec<u8>,
|
pub highlight_css: Vec<u8>,
|
||||||
pub tomorrow_night_css: Vec<u8>,
|
pub tomorrow_night_css: Vec<u8>,
|
||||||
|
@ -41,6 +43,7 @@ impl Theme {
|
||||||
let mut theme = Theme {
|
let mut theme = Theme {
|
||||||
index: INDEX.to_owned(),
|
index: INDEX.to_owned(),
|
||||||
css: CSS.to_owned(),
|
css: CSS.to_owned(),
|
||||||
|
favicon: FAVICON.to_owned(),
|
||||||
js: JS.to_owned(),
|
js: JS.to_owned(),
|
||||||
highlight_css: HIGHLIGHT_CSS.to_owned(),
|
highlight_css: HIGHLIGHT_CSS.to_owned(),
|
||||||
tomorrow_night_css: TOMORROW_NIGHT_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);
|
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
|
// highlight.js
|
||||||
if let Ok(mut f) = File::open(&src.join("highlight.js")) {
|
if let Ok(mut f) = File::open(&src.join("highlight.js")) {
|
||||||
theme.highlight_js.clear();
|
theme.highlight_js.clear();
|
||||||
|
|
Loading…
Reference in New Issue