-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
26 lines (24 loc) · 857 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::fs;
use std::path::Path;
use std::process::Command;
fn optimize_images(image_dir: &str, target_dir: &str) {
fs::read_dir(Path::new(image_dir))
.expect("Failed to read image directory")
.for_each(|image| {
let input_file = image.expect("Cannot read imgae");
let output_file = Path::new(target_dir).join(input_file.file_name());
Command::new("convert")
.arg(input_file.path())
.arg("-resize")
.arg("x256")
.arg(output_file.with_extension("webp"))
.spawn()
.expect("Failed to convert image");
});
}
fn main() {
let image_dir = "public/images";
let target_dir = "target/site/images";
println!("cargo:rerun-if-changed={image_dir}");
optimize_images(image_dir, target_dir);
}