Skip to content

Add SVG favicon. #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also somehow be replaced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In index.hbs I replaced {{ favicon }} with just the literal text favicon.png and favicon.svg. There didn't seem to be a reason to have this because it is a fixed value and is not configurable.

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