From 215af5dc1e5236f4bff5d6a6401d4a473077de52 Mon Sep 17 00:00:00 2001 From: mlange-42 Date: Wed, 18 Jan 2023 12:38:46 +0100 Subject: [PATCH] use CSS to hide elements on certain themes --- src/book/init.rs | 3 +++ src/renderer/html_handlebars/hbs_renderer.rs | 1 + src/theme/css/exclude.css | 23 ++++++++++++++++++++ src/theme/mod.rs | 6 +++++ tests/init.rs | 1 + 5 files changed, 34 insertions(+) create mode 100644 src/theme/css/exclude.css diff --git a/src/book/init.rs b/src/book/init.rs index dd3fa8b0..97dc88d4 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -143,6 +143,9 @@ impl BookBuilder { let mut variables_css = File::create(cssdir.join("variables.css"))?; variables_css.write_all(theme::VARIABLES_CSS)?; + let mut excludes_css = File::create(cssdir.join("exclude.css"))?; + excludes_css.write_all(theme::EXCLUDES_CSS)?; + let mut favicon = File::create(themedir.join("favicon.png"))?; favicon.write_all(theme::FAVICON_PNG)?; diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 1b648dac..920a899e 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -229,6 +229,7 @@ impl HtmlHandlebars { write_file(destination, "css/print.css", &theme.print_css)?; } write_file(destination, "css/variables.css", &theme.variables_css)?; + write_file(destination, "css/exclude.css", &theme.excludes_css)?; if let Some(contents) = &theme.favicon_png { write_file(destination, "favicon.png", contents)?; } diff --git a/src/theme/css/exclude.css b/src/theme/css/exclude.css new file mode 100644 index 00000000..38e7321f --- /dev/null +++ b/src/theme/css/exclude.css @@ -0,0 +1,23 @@ +.light .no-light { + visibility: hidden; +} + +.rust .no-rust { + visibility: hidden; +} + +.navy .no-navy { + visibility: hidden; +} + +.ayu .no-ayu { + visibility: hidden; +} + +.coal .no-coal { + visibility: hidden; +} + +.navy, .ayu, .coal .no-dark { + visibility: hidden; +} diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 7af5e2b7..dbc0c8b9 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -21,6 +21,7 @@ pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css"); pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css"); pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css"); pub static VARIABLES_CSS: &[u8] = include_bytes!("css/variables.css"); +pub static EXCLUDES_CSS: &[u8] = include_bytes!("css/exclude.css"); pub static FAVICON_PNG: &[u8] = include_bytes!("favicon.png"); pub static FAVICON_SVG: &[u8] = include_bytes!("favicon.svg"); pub static JS: &[u8] = include_bytes!("book.js"); @@ -54,6 +55,7 @@ pub struct Theme { pub general_css: Vec, pub print_css: Vec, pub variables_css: Vec, + pub excludes_css: Vec, pub favicon_png: Option>, pub favicon_svg: Option>, pub js: Vec, @@ -91,6 +93,7 @@ impl Theme { theme_dir.join("css/variables.css"), &mut theme.variables_css, ), + (theme_dir.join("css/exclude.css"), &mut theme.excludes_css), (theme_dir.join("highlight.js"), &mut theme.highlight_js), (theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js), (theme_dir.join("highlight.css"), &mut theme.highlight_css), @@ -153,6 +156,7 @@ impl Default for Theme { general_css: GENERAL_CSS.to_owned(), print_css: PRINT_CSS.to_owned(), variables_css: VARIABLES_CSS.to_owned(), + excludes_css: EXCLUDES_CSS.to_owned(), favicon_png: Some(FAVICON_PNG.to_owned()), favicon_svg: Some(FAVICON_SVG.to_owned()), js: JS.to_owned(), @@ -213,6 +217,7 @@ mod tests { "css/general.css", "css/print.css", "css/variables.css", + "css/exclude.css", "book.js", "highlight.js", "tomorrow-night.css", @@ -240,6 +245,7 @@ mod tests { general_css: Vec::new(), print_css: Vec::new(), variables_css: Vec::new(), + excludes_css: Vec::new(), favicon_png: Some(Vec::new()), favicon_svg: Some(Vec::new()), js: Vec::new(), diff --git a/tests/init.rs b/tests/init.rs index 1c3b962b..c429f3b1 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -119,6 +119,7 @@ fn copy_theme() { "css/general.css", "css/print.css", "css/variables.css", + "css/exclude.css", "favicon.png", "favicon.svg", "highlight.css",