From 9b0ccfb46a709a49f1aceeb98f2e57c40748dae4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 14 Apr 2021 15:16:45 -0700 Subject: [PATCH] Fix fa-github repository icon --- guide/src/format/configuration/renderers.md | 4 ++-- guide/src/format/mdbook.md | 6 +++--- guide/src/format/theme/index-hbs.md | 2 +- src/renderer/html_handlebars/hbs_renderer.rs | 12 +++++++++++- src/renderer/html_handlebars/helpers/fontawesome.rs | 4 ++++ src/theme/index.hbs | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/guide/src/format/configuration/renderers.md b/guide/src/format/configuration/renderers.md index df105c8d74..cf6a0971fc 100644 --- a/guide/src/format/configuration/renderers.md +++ b/guide/src/format/configuration/renderers.md @@ -43,7 +43,7 @@ The following configuration options are available: - **git-repository-url:** A url to the git repository for the book. If provided an icon link will be output in the menu bar of the book. - **git-repository-icon:** The FontAwesome icon class to use for the git - repository link. Defaults to `fa-github`. + repository link. Defaults to `fab-github`. - **edit-url-template:** Edit url template, when provided shows a "Suggest an edit" button for directly jumping to editing the currently viewed page. For e.g. GitHub projects set this to @@ -135,7 +135,7 @@ additional-css = ["custom.css", "custom2.css"] additional-js = ["custom.js"] no-section-label = false git-repository-url = "https://github.com/rust-lang/mdBook" -git-repository-icon = "fa-github" +git-repository-icon = "fab-github" edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}" site-url = "/example-book/" cname = "myproject.rs" diff --git a/guide/src/format/mdbook.md b/guide/src/format/mdbook.md index a3d8676620..fd59c30693 100644 --- a/guide/src/format/mdbook.md +++ b/guide/src/format/mdbook.md @@ -205,9 +205,9 @@ contents (sidebar) by including a `\{{#title ...}}` near the top of the page. ## Font-Awesome icons mdBook includes a copy of [Font Awesome Free's](https://fontawesome.com) -MIT-licensed SVG files. It emulates the `` syntax, but converts -the results to inline SVG. Only the regular, solid, and brands icons are -included; paid features like the light icons are not. +MIT-licensed SVG files. It emulates the `` syntax, but converts the results +to inline SVG. Only the regular, solid, and brands icons are included; paid +features like the light icons are not. For example, given this HTML syntax: diff --git a/guide/src/format/theme/index-hbs.md b/guide/src/format/theme/index-hbs.md index d85ff59b2e..fae38ecfb0 100644 --- a/guide/src/format/theme/index-hbs.md +++ b/guide/src/format/theme/index-hbs.md @@ -87,7 +87,7 @@ They are used like this ```handlebars {{#previous}} {{/previous}} ``` diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 8e5b56cbbc..5fc74fe0bc 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -665,9 +665,19 @@ fn make_data( let git_repository_icon = match html_config.git_repository_icon { Some(ref git_repository_icon) => git_repository_icon, - None => "fa-github", + None => "fab-github", + }; + let git_repository_icon_class = match git_repository_icon.split('-').next() { + Some("fa") => "regular", + Some("fas") => "solid", + Some("fab") => "brands", + _ => "regular", }; data.insert("git_repository_icon".to_owned(), json!(git_repository_icon)); + data.insert( + "git_repository_icon_class".to_owned(), + json!(git_repository_icon_class), + ); let mut chapters = vec![]; diff --git a/src/renderer/html_handlebars/helpers/fontawesome.rs b/src/renderer/html_handlebars/helpers/fontawesome.rs index f0eb00c72c..46967cb0ac 100644 --- a/src/renderer/html_handlebars/helpers/fontawesome.rs +++ b/src/renderer/html_handlebars/helpers/fontawesome.rs @@ -27,6 +27,10 @@ pub fn fa_helper( let name = if name.starts_with("fa-") { &name[3..] + } else if name.starts_with("fab-") { + &name[4..] + } else if name.starts_with("fas-") { + &name[4..] } else { &name[..] }; diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 4dd9069d23..7d96888aae 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -144,7 +144,7 @@ {{/if}} {{#if git_repository_url}} - {{fa "solid" git_repository_icon}} + {{fa git_repository_icon_class git_repository_icon}} {{/if}} {{#if git_repository_edit_url}}