Skip to content

Commit e22d06d

Browse files
committed
Use embedded SVG instead of fonts for icons
The [downsides of icon fonts] are well-documented, and also, why ship all of the icons when it only uses 14? [downsides of icon fonts]: https://speakerdeck.com/ninjanails/death-to-icon-fonts
1 parent 39d7130 commit e22d06d

File tree

17 files changed

+99
-2753
lines changed

17 files changed

+99
-2753
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ serde_json = "1.0"
3333
shlex = "0.1"
3434
tempfile = "3.0"
3535
toml = "0.5.1"
36+
font-awesome-as-a-crate = "0.1.2"
3637

3738
# Watch feature
3839
notify = { version = "4.0", optional = true }

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -207,41 +207,6 @@ impl HtmlHandlebars {
207207
write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
208208
write_file(destination, "highlight.js", &theme.highlight_js)?;
209209
write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
210-
write_file(
211-
destination,
212-
"FontAwesome/css/font-awesome.css",
213-
theme::FONT_AWESOME,
214-
)?;
215-
write_file(
216-
destination,
217-
"FontAwesome/fonts/fontawesome-webfont.eot",
218-
theme::FONT_AWESOME_EOT,
219-
)?;
220-
write_file(
221-
destination,
222-
"FontAwesome/fonts/fontawesome-webfont.svg",
223-
theme::FONT_AWESOME_SVG,
224-
)?;
225-
write_file(
226-
destination,
227-
"FontAwesome/fonts/fontawesome-webfont.ttf",
228-
theme::FONT_AWESOME_TTF,
229-
)?;
230-
write_file(
231-
destination,
232-
"FontAwesome/fonts/fontawesome-webfont.woff",
233-
theme::FONT_AWESOME_WOFF,
234-
)?;
235-
write_file(
236-
destination,
237-
"FontAwesome/fonts/fontawesome-webfont.woff2",
238-
theme::FONT_AWESOME_WOFF2,
239-
)?;
240-
write_file(
241-
destination,
242-
"FontAwesome/fonts/FontAwesome.ttf",
243-
theme::FONT_AWESOME_TTF,
244-
)?;
245210
if html_config.copy_fonts {
246211
write_file(destination, "fonts/fonts.css", theme::fonts::CSS)?;
247212
for (file_name, contents) in theme::fonts::LICENSES.iter() {
@@ -308,6 +273,7 @@ impl HtmlHandlebars {
308273
handlebars.register_helper("previous", Box::new(helpers::navigation::previous));
309274
handlebars.register_helper("next", Box::new(helpers::navigation::next));
310275
handlebars.register_helper("theme_option", Box::new(helpers::theme::theme_option));
276+
handlebars.register_helper("fa", Box::new(helpers::fontawesome::fa_helper));
311277
}
312278

313279
/// Copy across any additional CSS and JavaScript files which the book
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError};
2+
use font_awesome_as_a_crate as fa;
3+
4+
pub fn fa_helper(
5+
h: &Helper<'_, '_>,
6+
_r: &Handlebars<'_>,
7+
_ctx: &Context,
8+
_rc: &mut RenderContext<'_, '_>,
9+
out: &mut dyn Output,
10+
) -> Result<(), RenderError> {
11+
trace!("fa_helper (handlebars helper)");
12+
13+
let type_ = h.param(0).and_then(|v| v.value().as_str()).and_then(|v| fa::Type::from_str(v).ok()).ok_or_else(|| {
14+
RenderError::new("Param 0 with String type is required for fontawesome helper.")
15+
})?;
16+
17+
let name = h.param(1).and_then(|v| v.value().as_str()).ok_or_else(|| {
18+
RenderError::new("Param 1 with String type is required for fontawesome helper.")
19+
})?;
20+
21+
trace!("fa_helper: {} {}", type_, name);
22+
23+
let name = if name.starts_with("fa-") {
24+
&name[3..]
25+
} else {
26+
&name[..]
27+
};
28+
29+
if let Some(id) = h.param(2).and_then(|v| v.value().as_str()) {
30+
out.write(&format!("<span class=fa-svg id=\"{}\">", id))?;
31+
} else {
32+
out.write("<span class=fa-svg>")?;
33+
}
34+
out.write(fa::svg(type_, name).map_err(|_| RenderError::new(format!("Missing font {}", name)))?)?;
35+
out.write("</span>")?;
36+
37+
Ok(())
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod navigation;
22
pub mod theme;
33
pub mod toc;
4+
pub mod fontawesome;

src/theme/FontAwesome/css/font-awesome.min.css

Lines changed: 0 additions & 4 deletions
This file was deleted.
-132 KB
Binary file not shown.
-162 KB
Binary file not shown.

src/theme/FontAwesome/fonts/fontawesome-webfont.svg

Lines changed: 0 additions & 2671 deletions
This file was deleted.
-162 KB
Binary file not shown.

0 commit comments

Comments
 (0)