From 122c9884778d706d5abbc4a8ad646d6d6f2cfb88 Mon Sep 17 00:00:00 2001 From: Aphek Date: Tue, 19 May 2020 03:09:25 -0300 Subject: [PATCH] Rename config from no-copy-fonts to copy-fonts --- book-example/src/format/config.md | 4 +-- src/config.rs | 29 ++++++++++++++++++-- src/renderer/html_handlebars/hbs_renderer.rs | 6 ++-- src/theme/index.hbs | 4 +-- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/book-example/src/format/config.md b/book-example/src/format/config.md index d1cd8abf..c1a97aa7 100644 --- a/book-example/src/format/config.md +++ b/book-example/src/format/config.md @@ -177,7 +177,7 @@ The following configuration options are available: that occur in code blocks and code spans. Defaults to `false`. - **mathjax-support:** Adds support for [MathJax](mathjax.md). Defaults to `false`. -- **no-copy-fonts:** Prevents fonts.css and respective font files from being copied. Defaults to `false`. +- **copy-fonts:** Copies fonts.css and respective font files to the output directory and use them in the default theme. Defaults to `true`. - **google-analytics:** If you use Google Analytics, this option lets you enable it by simply specifying your ID in the configuration file. - **additional-css:** If you need to slightly change the appearance of your book @@ -253,7 +253,7 @@ default-theme = "light" preferred-dark-theme = "navy" curly-quotes = true mathjax-support = false -no-copy-fonts = false +copy-fonts = true google-analytics = "123456" additional-css = ["custom.css", "custom2.css"] additional-js = ["custom.js"] diff --git a/src/config.rs b/src/config.rs index b9bd2d71..eae360cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -475,7 +475,7 @@ pub enum RustEdition { } /// Configuration for the HTML renderer. -#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct HtmlConfig { /// The theme directory, if specified. @@ -489,8 +489,8 @@ pub struct HtmlConfig { pub curly_quotes: bool, /// Should mathjax be enabled? pub mathjax_support: bool, - /// Prevents fonts.css and respective font files from being copied. - pub no_copy_fonts: bool, + /// Whether to fonts.css and respective font files to the output directory. + pub copy_fonts: bool, /// An optional google analytics code. pub google_analytics: Option, /// Additional CSS stylesheets to include in the rendered page's ``. @@ -521,6 +521,29 @@ pub struct HtmlConfig { pub livereload_url: Option, } +impl Default for HtmlConfig { + fn default() -> HtmlConfig { + HtmlConfig { + theme: None, + default_theme: None, + preferred_dark_theme: None, + curly_quotes: false, + mathjax_support: false, + copy_fonts: true, + google_analytics: None, + additional_css: Vec::new(), + additional_js: Vec::new(), + fold: Fold::default(), + playpen: Playpen::default(), + no_section_label: false, + search: None, + git_repository_url: None, + git_repository_icon: None, + livereload_url: None, + } + } +} + impl HtmlConfig { /// Returns the directory of theme from the provided root directory. If the /// directory is not present it will append the default directory of "theme" diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 227cdfa1..9ebe11aa 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -179,7 +179,7 @@ impl HtmlHandlebars { "FontAwesome/fonts/FontAwesome.ttf", theme::FONT_AWESOME_TTF, )?; - if !html_config.no_copy_fonts { + if html_config.copy_fonts { write_file(destination, "fonts/fonts.css", theme::fonts::CSS)?; for (file_name, contents) in theme::fonts::OPEN_SANS.iter() { write_file(destination, file_name, contents)?; @@ -455,8 +455,8 @@ fn make_data( data.insert("mathjax_support".to_owned(), json!(true)); } - if html_config.no_copy_fonts { - data.insert("no_copy_fonts".to_owned(), json!(true)); + if html_config.copy_fonts { + data.insert("copy_fonts".to_owned(), json!(true)); } // Add check to see if there is an additional style diff --git a/src/theme/index.hbs b/src/theme/index.hbs index e0ad622d..e8a92dd0 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -24,9 +24,9 @@ - {{#unless no_copy_fonts}} + {{#if copy_fonts}} - {{/unless}} + {{/if}}