Skip to content

Commit

Permalink
Fix fa-github repository icon
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Jun 27, 2022
1 parent f5d4f6e commit ec0479e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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"
Expand Down Expand Up @@ -142,7 +142,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` which looks like <i class="fa fa-github"></i>.
repository link. Defaults to `fab-github` which looks like <i class="fa fab-github"></i>.
If you are not using GitHub, another option to consider is `fa-code-fork` which looks like <i class="fa fa-code-fork"></i>.
- **edit-url-template:** Edit url template, when provided shows a
"Suggest an edit" button (which looks like <i class="fa fa-edit"></i>) for directly jumping to editing the currently
Expand Down
6 changes: 3 additions & 3 deletions guide/src/format/mdbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,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 `<i class="fa">` 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 `<i>` 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:

Expand Down
2 changes: 1 addition & 1 deletion guide/src/format/theme/index-hbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ They are used like this
```handlebars
{{#previous}}
<a href="{{link}}" class="nav-chapters previous">
<i class="fa fa-angle-left"></i>
{{fa "solid" "angle-left"}}
</a>
{{/previous}}
```
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,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![];

Expand Down
4 changes: 4 additions & 0 deletions src/renderer/html_handlebars/helpers/fontawesome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]
};
Expand Down
2 changes: 1 addition & 1 deletion src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
{{/if}}
{{#if git_repository_url}}
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
{{fa "solid" git_repository_icon}}
{{fa git_repository_icon_class git_repository_icon}}
</a>
{{/if}}
{{#if git_repository_edit_url}}
Expand Down

0 comments on commit ec0479e

Please sign in to comment.