From 1ecd5fd58f8d7718c8cd72e8cff4f18cf6eacfca Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Fri, 2 Jun 2023 17:55:44 -0500 Subject: [PATCH] added: minify header and flag --- files/README/source/docs/header.meta | 1 + src/metafile/dir/node.rs | 6 +++++- src/metafile/header.rs | 3 +++ src/options.rs | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/files/README/source/docs/header.meta b/files/README/source/docs/header.meta index 48dca52..1bda89c 100644 --- a/files/README/source/docs/header.meta +++ b/files/README/source/docs/header.meta @@ -41,6 +41,7 @@ normal definition blocks. - filetype = **STRING** - change the filetype of the output file - equal_arrays = **BOOL** - if true, panics if arrays in the same pattern have different sizes - pandoc = **BOOL** - toggles if pandoc is ran on this file to convert between filetypes, defaults to *true* in **source** dir, and *false* in **pattern** dir. +- minify = **BOOL** - toggles html minification ### source diff --git a/src/metafile/dir/node.rs b/src/metafile/dir/node.rs index 40e3d0c..d9b2a05 100644 --- a/src/metafile/dir/node.rs +++ b/src/metafile/dir/node.rs @@ -86,7 +86,11 @@ impl<'a> DirNode<'a> { file.merge(&self.global); match file.construct() { Ok(str) => { - fs::write(file.dest()?, minify(str.as_bytes(), &HTML_CFG))?; + if file.header.minify && self.opts.minify { + fs::write(file.dest()?, minify(str.as_bytes(), &HTML_CFG))?; + } else { + fs::write(file.dest()?, str)?; + } } Err(e) => { // print a line to stderr about failure but continue with other files diff --git a/src/metafile/header.rs b/src/metafile/header.rs index d99d5c4..a895ac3 100644 --- a/src/metafile/header.rs +++ b/src/metafile/header.rs @@ -11,6 +11,7 @@ pub struct Header { pub pandoc: Option, pub ignore: bool, pub copy_only: bool, + pub minify: bool, } impl Header { @@ -25,6 +26,7 @@ impl Header { pandoc: None, ignore: false, copy_only: false, + minify: true, } } } @@ -43,6 +45,7 @@ impl From> for Header { "source" => header.source = val.to_string(), "ignore" => header.ignore = val == "true", "copy_only" => header.copy_only = val == "true", + "minify" => header.copy_only = val == "true", _ => continue, } } diff --git a/src/options.rs b/src/options.rs index 704d2cb..11e8a2c 100644 --- a/src/options.rs +++ b/src/options.rs @@ -53,6 +53,9 @@ pub struct Opts { /// don't call pandoc on source files #[arg(long, default_value_t = false)] pub no_pandoc: bool, + /// don't minify resulting html + #[arg(long, default_value_t = false)] + pub no_minify: bool, } #[derive(Debug, Clone, Default)] @@ -72,6 +75,7 @@ pub struct Options { pub clean: bool, pub no_pandoc: bool, pub new: bool, + pub minify: bool, } impl Options { @@ -92,6 +96,7 @@ impl Options { clean: false, no_pandoc: false, new: false, + minify: true, } } } @@ -109,6 +114,7 @@ impl TryFrom for Options { opts.no_pandoc = value.no_pandoc; opts.new = value.new; opts.parallel = value.parallel; + opts.minify = !value.no_minify; opts.root = if let Some(root) = value.root.as_deref() { PathBuf::from(root).canonicalize() -- 2.44.2