From 5bfdf9fcc821a4144b0c62ef03a053616d0632c2 Mon Sep 17 00:00:00 2001 From: Jason Liquorish Date: Mon, 15 Oct 2018 19:48:54 +0100 Subject: [PATCH] Added git-repository-icon option Updated documentation and added tests. --- book-example/src/format/config.md | 4 ++++ src/config.rs | 9 ++++++++- src/renderer/html_handlebars/hbs_renderer.rs | 7 ++++++- src/theme/index.hbs | 6 +++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/book-example/src/format/config.md b/book-example/src/format/config.md index 3f0fa278..6eb394dd 100644 --- a/book-example/src/format/config.md +++ b/book-example/src/format/config.md @@ -149,6 +149,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: diff --git a/src/config.rs b/src/config.rs index 736795dd..97795b66 100644 --- a/src/config.rs +++ b/src/config.rs @@ -440,8 +440,11 @@ pub struct HtmlConfig { pub no_section_label: bool, /// Search settings. If `None`, the default will be used. pub search: Option, - /// Git repository url. If 'None', the git button will not be shown. + /// Git repository url. If `None`, the git button will not be shown. pub git_repository_url: Option, + /// FontAwesome icon class to use for the Git repository link. + /// Defaults to `fa-github` if `None`. + pub git_repository_icon: Option, } impl HtmlConfig { @@ -573,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 @@ -610,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() }; diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index ebf20feb..ff28f9da 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -455,8 +455,13 @@ 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)); + 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![]; diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 21c0b0a4..e2577e03 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -113,9 +113,9 @@ - {{#if git-repository-url}} - - + {{#if git_repository_url}} + + {{/if}}