Skip to content

Commit 15f3052

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 94f7578 commit 15f3052

File tree

17 files changed

+105
-2753
lines changed

17 files changed

+105
-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 = "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
@@ -218,41 +218,6 @@ impl HtmlHandlebars {
218218
write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
219219
write_file(destination, "highlight.js", &theme.highlight_js)?;
220220
write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
221-
write_file(
222-
destination,
223-
"FontAwesome/css/font-awesome.css",
224-
theme::FONT_AWESOME,
225-
)?;
226-
write_file(
227-
destination,
228-
"FontAwesome/fonts/fontawesome-webfont.eot",
229-
theme::FONT_AWESOME_EOT,
230-
)?;
231-
write_file(
232-
destination,
233-
"FontAwesome/fonts/fontawesome-webfont.svg",
234-
theme::FONT_AWESOME_SVG,
235-
)?;
236-
write_file(
237-
destination,
238-
"FontAwesome/fonts/fontawesome-webfont.ttf",
239-
theme::FONT_AWESOME_TTF,
240-
)?;
241-
write_file(
242-
destination,
243-
"FontAwesome/fonts/fontawesome-webfont.woff",
244-
theme::FONT_AWESOME_WOFF,
245-
)?;
246-
write_file(
247-
destination,
248-
"FontAwesome/fonts/fontawesome-webfont.woff2",
249-
theme::FONT_AWESOME_WOFF2,
250-
)?;
251-
write_file(
252-
destination,
253-
"FontAwesome/fonts/FontAwesome.ttf",
254-
theme::FONT_AWESOME_TTF,
255-
)?;
256221
if html_config.copy_fonts {
257222
write_file(destination, "fonts/fonts.css", theme::fonts::CSS)?;
258223
for (file_name, contents) in theme::fonts::LICENSES.iter() {
@@ -319,6 +284,7 @@ impl HtmlHandlebars {
319284
handlebars.register_helper("previous", Box::new(helpers::navigation::previous));
320285
handlebars.register_helper("next", Box::new(helpers::navigation::next));
321286
handlebars.register_helper("theme_option", Box::new(helpers::theme::theme_option));
287+
handlebars.register_helper("fa", Box::new(helpers::fontawesome::fa_helper));
322288
}
323289

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

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)