Merge pull request #802 from Bassetts/git-button

Implement a git repository button
This commit is contained in:
Michael Bryan 2018-10-23 19:16:45 +08:00 committed by GitHub
commit b4538da9c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 2701 additions and 640 deletions

View File

@ -163,6 +163,10 @@ The following configuration options are available:
- **playpen:** A subtable for configuring various playpen settings. - **playpen:** A subtable for configuring various playpen settings.
- **search:** A subtable for configuring the in-browser search functionality. - **search:** A subtable for configuring the in-browser search functionality.
mdBook must be compiled with the `search` feature enabled (on by default). 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: Available configuration options for the `[output.html.playpen]` table:

View File

@ -440,6 +440,11 @@ pub struct HtmlConfig {
pub no_section_label: bool, pub no_section_label: bool,
/// Search settings. If `None`, the default will be used. /// Search settings. If `None`, the default will be used.
pub search: Option<Search>, 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 { impl HtmlConfig {
@ -571,6 +576,8 @@ mod tests {
curly-quotes = true curly-quotes = true
google-analytics = "123456" google-analytics = "123456"
additional-css = ["./foo/bar/baz.css"] additional-css = ["./foo/bar/baz.css"]
git-repository-url = "https://foo.com/"
git-repository-icon = "fa-code-fork"
[output.html.playpen] [output.html.playpen]
editable = true editable = true
@ -608,6 +615,8 @@ mod tests {
additional_css: vec![PathBuf::from("./foo/bar/baz.css")], additional_css: vec![PathBuf::from("./foo/bar/baz.css")],
theme: Some(PathBuf::from("./themedir")), theme: Some(PathBuf::from("./themedir")),
playpen: playpen_should_be, playpen: playpen_should_be,
git_repository_url: Some(String::from("https://foo.com/")),
git_repository_icon: Some(String::from("fa-code-fork")),
..Default::default() ..Default::default()
}; };

View File

@ -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![]; let mut chapters = vec![];
for item in book.iter() { for item in book.iter() {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 348 KiB

After

Width:  |  Height:  |  Size: 434 KiB

View File

@ -63,9 +63,12 @@ a > .hljs {
margin: 0; margin: 0;
} }
#print-button { .right-buttons {
margin: 0 15px; margin: 0 15px;
} }
.right-buttons a {
text-decoration: none;
}
html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-container { html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-container {
transform: translateY(-60px); transform: translateY(-60px);

View File

@ -113,6 +113,11 @@
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book"> <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> <i id="print-button" class="fa fa-print"></i>
</a> </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> </div>
</div> </div>