Skip to content

Commit

Permalink
Adds minify option to build command (#2776)
Browse files Browse the repository at this point in the history
Now the build command supports minification and you can run `zola build
--minify` to get the minified result only at build time. Closes #1924.
  • Loading branch information
ogarcia authored Jan 19, 2025
1 parent 897d8f5 commit 3f9bd81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -68,6 +68,7 @@ fn main() {
output_dir.as_deref(),
force,
drafts,
minify,
) {
Ok(()) => messages::report_elapsed_time(start),
Err(e) => {
Expand Down

0 comments on commit 3f9bd81

Please sign in to comment.