diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 60c982ee37..5485e78f2b 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -175,6 +175,10 @@ impl Site { self.output_path = path.as_ref().to_path_buf(); } + pub fn minify(&mut self) { + self.config.minify_html = true; + } + /// Reads all .md files in the `content` directory and create pages/sections /// out of them pub fn load(&mut self) -> Result<()> { diff --git a/src/cli.rs b/src/cli.rs index a7d3ce7d33..4c6708f0b4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -49,6 +49,10 @@ pub enum Command { /// Include drafts when loading the site #[clap(long)] drafts: bool, + + /// Minify generated HTML files + #[clap(long)] + minify: bool, }, /// Serve the site. Rebuild and reload on change automatically diff --git a/src/cmd/build.rs b/src/cmd/build.rs index d088743687..75daa7b376 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -12,6 +12,7 @@ pub fn build( output_dir: Option<&Path>, force: bool, include_drafts: bool, + minify: bool, ) -> Result<()> { let mut site = Site::new(root_dir, config_file)?; if let Some(output_dir) = output_dir { @@ -30,6 +31,9 @@ pub fn build( if include_drafts { site.include_drafts(); } + if minify { + site.minify(); + } site.load()?; messages::notify_site_size(&site); messages::warn_about_ignored_pages(&site); diff --git a/src/main.rs b/src/main.rs index ec520fed41..58e784ae28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ fn main() { std::process::exit(1); } } - Command::Build { base_url, output_dir, force, drafts } => { + Command::Build { base_url, output_dir, force, drafts, minify } => { console::info("Building site..."); let start = Instant::now(); let (root_dir, config_file) = get_config_file_path(&cli_dir, &cli.config); @@ -68,6 +68,7 @@ fn main() { output_dir.as_deref(), force, drafts, + minify, ) { Ok(()) => messages::report_elapsed_time(start), Err(e) => {