use anyhow::Error;
use glob::glob;
use html_minifier::minify;
use std::{
fs::{read_to_string, File},
io::Write,
process::Command,
};
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=migrations");
println!("cargo:rerun-if-changed=templates");
Command::new("rm").args(["-rf", "templates_min"]).output()?;
Command::new("cp")
.args(["-r", "templates", "templates_min"])
.output()?;
let templates = glob("templates_min/**/*.html")?;
for path in templates {
let path = path?;
if !path.is_file() {
continue;
}
let html = read_to_string(&path)?;
let minified = minify(html)?.replace('\n', "");
File::create(path)?.write_all(minified.as_bytes())?;
}
Ok(())
}