Skip to content

Commit 4699269

Browse files
committed
Add SVG favicon.
1 parent c1ed6ee commit 4699269

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

book-example/src/format/theme/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Here are the files you can override:
2222
- **_highlight.js_** is the JavaScript that is used to highlight code snippets,
2323
you should not need to modify this.
2424
- **_highlight.css_** is the theme used for the code highlighting.
25-
- **_favicon.png_** the favicon that will be used.
25+
- **_favicon.svg_** and **_favicon.png_** the favicon that will be used. The SVG
26+
version is used by [newer browsers].
2627

2728
Generally, when you want to tweak the theme, you don't need to override all the
2829
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
4041
built-in `navy` theme.
4142

4243
[`output.html.preferred-dark-theme`]: ../config.md#html-renderer-options
44+
[newer browsers]: https://caniuse.com/#feat=link-icon-svg

src/book/init.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ impl BookBuilder {
143143
variables_css.write_all(theme::VARIABLES_CSS)?;
144144

145145
let mut favicon = File::create(themedir.join("favicon.png"))?;
146-
favicon.write_all(theme::FAVICON)?;
146+
favicon.write_all(theme::FAVICON_PNG)?;
147+
148+
let mut favicon = File::create(themedir.join("favicon.svg"))?;
149+
favicon.write_all(theme::FAVICON_SVG)?;
147150

148151
let mut js = File::create(themedir.join("book.js"))?;
149152
js.write_all(theme::JS)?;

src/renderer/html_handlebars/hbs_renderer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ impl HtmlHandlebars {
192192
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
193193
write_file(destination, "css/print.css", &theme.print_css)?;
194194
write_file(destination, "css/variables.css", &theme.variables_css)?;
195-
write_file(destination, "favicon.png", &theme.favicon)?;
195+
write_file(destination, "favicon.png", &theme.favicon_png)?;
196+
write_file(destination, "favicon.svg", &theme.favicon_svg)?;
196197
write_file(destination, "highlight.css", &theme.highlight_css)?;
197198
write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?;
198199
write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
@@ -562,7 +563,6 @@ fn make_data(
562563
"description".to_owned(),
563564
json!(config.book.description.clone().unwrap_or_default()),
564565
);
565-
data.insert("favicon".to_owned(), json!("favicon.png"));
566566
if let Some(ref livereload) = html_config.livereload_url {
567567
data.insert("livereload".to_owned(), json!(livereload));
568568
}

src/theme/favicon.svg

+22
Loading

src/theme/index.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<meta name="viewport" content="width=device-width, initial-scale=1">
2121
<meta name="theme-color" content="#ffffff" />
2222

23-
<link rel="shortcut icon" href="{{ path_to_root }}{{ favicon }}">
23+
<link rel="icon" href="{{ path_to_root }}favicon.svg">
24+
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
2425
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
2526
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
2627
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">

src/theme/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css");
2121
pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css");
2222
pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css");
2323
pub static VARIABLES_CSS: &[u8] = include_bytes!("css/variables.css");
24-
pub static FAVICON: &[u8] = include_bytes!("favicon.png");
24+
pub static FAVICON_PNG: &[u8] = include_bytes!("favicon.png");
25+
pub static FAVICON_SVG: &[u8] = include_bytes!("favicon.svg");
2526
pub static JS: &[u8] = include_bytes!("book.js");
2627
pub static HIGHLIGHT_JS: &[u8] = include_bytes!("highlight.js");
2728
pub static TOMORROW_NIGHT_CSS: &[u8] = include_bytes!("tomorrow-night.css");
@@ -53,7 +54,8 @@ pub struct Theme {
5354
pub general_css: Vec<u8>,
5455
pub print_css: Vec<u8>,
5556
pub variables_css: Vec<u8>,
56-
pub favicon: Vec<u8>,
57+
pub favicon_png: Vec<u8>,
58+
pub favicon_svg: Vec<u8>,
5759
pub js: Vec<u8>,
5860
pub highlight_css: Vec<u8>,
5961
pub tomorrow_night_css: Vec<u8>,
@@ -89,7 +91,8 @@ impl Theme {
8991
theme_dir.join("css/variables.css"),
9092
&mut theme.variables_css,
9193
),
92-
(theme_dir.join("favicon.png"), &mut theme.favicon),
94+
(theme_dir.join("favicon.png"), &mut theme.favicon_png),
95+
(theme_dir.join("favicon.svg"), &mut theme.favicon_svg),
9396
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
9497
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
9598
(theme_dir.join("highlight.css"), &mut theme.highlight_css),
@@ -129,7 +132,8 @@ impl Default for Theme {
129132
general_css: GENERAL_CSS.to_owned(),
130133
print_css: PRINT_CSS.to_owned(),
131134
variables_css: VARIABLES_CSS.to_owned(),
132-
favicon: FAVICON.to_owned(),
135+
favicon_png: FAVICON_PNG.to_owned(),
136+
favicon_svg: FAVICON_SVG.to_owned(),
133137
js: JS.to_owned(),
134138
highlight_css: HIGHLIGHT_CSS.to_owned(),
135139
tomorrow_night_css: TOMORROW_NIGHT_CSS.to_owned(),
@@ -182,6 +186,7 @@ mod tests {
182186
"redirect.hbs",
183187
"header.hbs",
184188
"favicon.png",
189+
"favicon.svg",
185190
"css/chrome.css",
186191
"css/fonts.css",
187192
"css/general.css",
@@ -214,7 +219,8 @@ mod tests {
214219
general_css: Vec::new(),
215220
print_css: Vec::new(),
216221
variables_css: Vec::new(),
217-
favicon: Vec::new(),
222+
favicon_png: Vec::new(),
223+
favicon_svg: Vec::new(),
218224
js: Vec::new(),
219225
highlight_css: Vec::new(),
220226
tomorrow_night_css: Vec::new(),

0 commit comments

Comments
 (0)