2023-12-11 15:18:43 +00:00
|
|
|
use anyhow::Error;
|
2023-12-18 17:00:25 +00:00
|
|
|
use fs_extra::dir::{copy, remove, CopyOptions};
|
2023-12-11 15:18:43 +00:00
|
|
|
use glob::glob;
|
|
|
|
use html_minifier::minify;
|
|
|
|
use std::{
|
|
|
|
fs::{read_to_string, File},
|
|
|
|
io::Write,
|
|
|
|
};
|
|
|
|
|
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
println!("cargo:rerun-if-changed=migrations");
|
|
|
|
println!("cargo:rerun-if-changed=templates");
|
|
|
|
|
2023-12-18 17:00:25 +00:00
|
|
|
remove("templates_min")?;
|
2023-12-11 15:18:43 +00:00
|
|
|
|
2023-12-18 17:00:25 +00:00
|
|
|
copy(
|
|
|
|
"templates",
|
|
|
|
"templates_min",
|
|
|
|
&CopyOptions::new().copy_inside(true),
|
|
|
|
)?;
|
2023-12-11 15:18:43 +00:00
|
|
|
|
|
|
|
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(())
|
|
|
|
}
|