From 4699269e496e8f8bb7c22f1b013dd18432a200d6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 17 May 2020 17:34:03 -0700 Subject: Add SVG favicon. --- book-example/src/format/theme/README.md | 4 +++- src/book/init.rs | 5 ++++- src/renderer/html_handlebars/hbs_renderer.rs | 4 ++-- src/theme/favicon.svg | 22 ++++++++++++++++++++++ src/theme/index.hbs | 3 ++- src/theme/mod.rs | 16 +++++++++++----- 6 files changed, 44 insertions(+), 10 deletions(-) create mode 100755 src/theme/favicon.svg diff --git a/book-example/src/format/theme/README.md b/book-example/src/format/theme/README.md index 5cf6a32d..d27a1fc7 100644 --- a/book-example/src/format/theme/README.md +++ b/book-example/src/format/theme/README.md @@ -22,7 +22,8 @@ Here are the files you can override: - **_highlight.js_** is the JavaScript that is used to highlight code snippets, you should not need to modify this. - **_highlight.css_** is the theme used for the code highlighting. -- **_favicon.png_** the favicon that will be used. +- **_favicon.svg_** and **_favicon.png_** the favicon that will be used. The SVG + version is used by [newer browsers]. Generally, when you want to tweak the theme, you don't need to override all the files. If you only need changes in the stylesheet, there is no point in @@ -40,3 +41,4 @@ If you completely replace all built-in themes, be sure to also set built-in `navy` theme. [`output.html.preferred-dark-theme`]: ../config.md#html-renderer-options +[newer browsers]: https://caniuse.com/#feat=link-icon-svg diff --git a/src/book/init.rs b/src/book/init.rs index 824fe72c..7ae00b65 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -143,7 +143,10 @@ impl BookBuilder { variables_css.write_all(theme::VARIABLES_CSS)?; let mut favicon = File::create(themedir.join("favicon.png"))?; - favicon.write_all(theme::FAVICON)?; + favicon.write_all(theme::FAVICON_PNG)?; + + let mut favicon = File::create(themedir.join("favicon.svg"))?; + favicon.write_all(theme::FAVICON_SVG)?; let mut js = File::create(themedir.join("book.js"))?; js.write_all(theme::JS)?; diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index b868f79c..4bf89e95 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -192,7 +192,8 @@ impl HtmlHandlebars { write_file(destination, "css/chrome.css", &theme.chrome_css)?; write_file(destination, "css/print.css", &theme.print_css)?; write_file(destination, "css/variables.css", &theme.variables_css)?; - write_file(destination, "favicon.png", &theme.favicon)?; + write_file(destination, "favicon.png", &theme.favicon_png)?; + write_file(destination, "favicon.svg", &theme.favicon_svg)?; write_file(destination, "highlight.css", &theme.highlight_css)?; write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?; write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?; @@ -562,7 +563,6 @@ fn make_data( "description".to_owned(), json!(config.book.description.clone().unwrap_or_default()), ); - data.insert("favicon".to_owned(), json!("favicon.png")); if let Some(ref livereload) = html_config.livereload_url { data.insert("livereload".to_owned(), json!(livereload)); } diff --git a/src/theme/favicon.svg b/src/theme/favicon.svg new file mode 100755 index 00000000..90e0ea58 --- /dev/null +++ b/src/theme/favicon.svg @@ -0,0 +1,22 @@ + + + + + diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 329318c4..f9d3c5aa 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -20,7 +20,8 @@ - + + diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 793aeb2e..4f81e2f9 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -21,7 +21,8 @@ pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css"); pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css"); pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css"); pub static VARIABLES_CSS: &[u8] = include_bytes!("css/variables.css"); -pub static FAVICON: &[u8] = include_bytes!("favicon.png"); +pub static FAVICON_PNG: &[u8] = include_bytes!("favicon.png"); +pub static FAVICON_SVG: &[u8] = include_bytes!("favicon.svg"); pub static JS: &[u8] = include_bytes!("book.js"); pub static HIGHLIGHT_JS: &[u8] = include_bytes!("highlight.js"); pub static TOMORROW_NIGHT_CSS: &[u8] = include_bytes!("tomorrow-night.css"); @@ -53,7 +54,8 @@ pub struct Theme { pub general_css: Vec, pub print_css: Vec, pub variables_css: Vec, - pub favicon: Vec, + pub favicon_png: Vec, + pub favicon_svg: Vec, pub js: Vec, pub highlight_css: Vec, pub tomorrow_night_css: Vec, @@ -89,7 +91,8 @@ impl Theme { theme_dir.join("css/variables.css"), &mut theme.variables_css, ), - (theme_dir.join("favicon.png"), &mut theme.favicon), + (theme_dir.join("favicon.png"), &mut theme.favicon_png), + (theme_dir.join("favicon.svg"), &mut theme.favicon_svg), (theme_dir.join("highlight.js"), &mut theme.highlight_js), (theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js), (theme_dir.join("highlight.css"), &mut theme.highlight_css), @@ -129,7 +132,8 @@ impl Default for Theme { general_css: GENERAL_CSS.to_owned(), print_css: PRINT_CSS.to_owned(), variables_css: VARIABLES_CSS.to_owned(), - favicon: FAVICON.to_owned(), + favicon_png: FAVICON_PNG.to_owned(), + favicon_svg: FAVICON_SVG.to_owned(), js: JS.to_owned(), highlight_css: HIGHLIGHT_CSS.to_owned(), tomorrow_night_css: TOMORROW_NIGHT_CSS.to_owned(), @@ -182,6 +186,7 @@ mod tests { "redirect.hbs", "header.hbs", "favicon.png", + "favicon.svg", "css/chrome.css", "css/fonts.css", "css/general.css", @@ -214,7 +219,8 @@ mod tests { general_css: Vec::new(), print_css: Vec::new(), variables_css: Vec::new(), - favicon: Vec::new(), + favicon_png: Vec::new(), + favicon_svg: Vec::new(), js: Vec::new(), highlight_css: Vec::new(), tomorrow_night_css: Vec::new(), -- cgit v1.2.3