Skip to content

Commit

Permalink
Add SVG favicon.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 23, 2020
1 parent c1ed6ee commit 4699269
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
4 changes: 3 additions & 1 deletion book-example/src/format/theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5 changes: 4 additions & 1 deletion src/book/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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));
}
Expand Down
22 changes: 22 additions & 0 deletions src/theme/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff" />

<link rel="shortcut icon" href="{{ path_to_root }}{{ favicon }}">
<link rel="icon" href="{{ path_to_root }}favicon.svg">
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
Expand Down
16 changes: 11 additions & 5 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -53,7 +54,8 @@ pub struct Theme {
pub general_css: Vec<u8>,
pub print_css: Vec<u8>,
pub variables_css: Vec<u8>,
pub favicon: Vec<u8>,
pub favicon_png: Vec<u8>,
pub favicon_svg: Vec<u8>,
pub js: Vec<u8>,
pub highlight_css: Vec<u8>,
pub tomorrow_night_css: Vec<u8>,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -182,6 +186,7 @@ mod tests {
"redirect.hbs",
"header.hbs",
"favicon.png",
"favicon.svg",
"css/chrome.css",
"css/fonts.css",
"css/general.css",
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 4699269

Please sign in to comment.