Skip to content

Commit

Permalink
Merge pull request rust-lang#802 from Bassetts/git-button
Browse files Browse the repository at this point in the history
Implement a git repository button
  • Loading branch information
Michael-F-Bryan authored Oct 23, 2018
2 parents c26d8c5 + 5060170 commit d6fb21d
Show file tree
Hide file tree
Showing 12 changed files with 2,701 additions and 640 deletions.
4 changes: 4 additions & 0 deletions book-example/src/format/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ The following configuration options are available:
- **playpen:** A subtable for configuring various playpen settings.
- **search:** A subtable for configuring the in-browser search functionality.
mdBook must be compiled with the `search` feature enabled (on by default).
- **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`.

Available configuration options for the `[output.html.playpen]` table:

Expand Down
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ pub struct HtmlConfig {
pub no_section_label: bool,
/// Search settings. If `None`, the default will be used.
pub search: Option<Search>,
/// Git repository url. If `None`, the git button will not be shown.
pub git_repository_url: Option<String>,
/// FontAwesome icon class to use for the Git repository link.
/// Defaults to `fa-github` if `None`.
pub git_repository_icon: Option<String>,
}

impl HtmlConfig {
Expand Down Expand Up @@ -571,6 +576,8 @@ mod tests {
curly-quotes = true
google-analytics = "123456"
additional-css = ["./foo/bar/baz.css"]
git-repository-url = "https://foo.com/"
git-repository-icon = "fa-code-fork"
[output.html.playpen]
editable = true
Expand Down Expand Up @@ -608,6 +615,8 @@ mod tests {
additional_css: vec![PathBuf::from("./foo/bar/baz.css")],
theme: Some(PathBuf::from("./themedir")),
playpen: playpen_should_be,
git_repository_url: Some(String::from("https://foo.com/")),
git_repository_icon: Some(String::from("fa-code-fork")),
..Default::default()
};

Expand Down
9 changes: 9 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ fn make_data(
)
}

if let Some(ref git_repository_url) = html_config.git_repository_url {
data.insert("git_repository_url".to_owned(), json!(git_repository_url));
}
let git_repository_icon = match html_config.git_repository_icon {
Some(ref git_repository_icon) => git_repository_icon,
None => "fa-github",
};
data.insert("git_repository_icon".to_owned(), json!(git_repository_icon));

let mut chapters = vec![];

for item in book.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/theme/FontAwesome/css/font-awesome.min.css

Large diffs are not rendered by default.

Binary file modified src/theme/FontAwesome/fonts/FontAwesome.otf
Binary file not shown.
Binary file modified src/theme/FontAwesome/fonts/fontawesome-webfont.eot
Binary file not shown.
3,305 changes: 2,668 additions & 637 deletions src/theme/FontAwesome/fonts/fontawesome-webfont.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/theme/FontAwesome/fonts/fontawesome-webfont.ttf
Binary file not shown.
Binary file modified src/theme/FontAwesome/fonts/fontawesome-webfont.woff
Binary file not shown.
Binary file modified src/theme/FontAwesome/fonts/fontawesome-webfont.woff2
Binary file not shown.
5 changes: 4 additions & 1 deletion src/theme/css/chrome.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ a > .hljs {
margin: 0;
}

#print-button {
.right-buttons {
margin: 0 15px;
}
.right-buttons a {
text-decoration: none;
}

html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-container {
transform: translateY(-60px);
Expand Down
5 changes: 5 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
{{#if git_repository_url}}
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
</a>
{{/if}}
</div>
</div>
</div>
Expand Down

0 comments on commit d6fb21d

Please sign in to comment.