html terminal
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -1,22 +1,30 @@ +#![feature(let_chains)] use std::fs; use std::io::prelude::*; use std::path::Path; -use minify_html::{minify, Cfg}; - pub fn process(input: impl AsRef<Path>) -> std::io::Result<()> { let mut f = fs::File::create(dbg!(Path::new("html").join(input.as_ref()))).unwrap(); - let mut buf = vec![]; - fs::File::open(Path::new("html-src").join(input.as_ref()))?.read_to_end(&mut buf)?; - let minified = minify( - &buf, - &Cfg { - minify_js: true, - minify_css: true, - ..Default::default() - }, - ); - f.write_all(&minified) + if !matches!( + input.as_ref().extension().unwrap().to_str().unwrap(), + "html" | "js" | "css" + ) { + return f.write_all(&std::fs::read(Path::new("html-src").join(input.as_ref()))?); + } + let mut c = std::process::Command::new("minify") + .arg(Path::new("html-src").join(input.as_ref())) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap(); + let mut o = c.stdout.take().unwrap(); + let mut buf = [0; 1024]; + while let Ok(x) = o.read(&mut buf) + && x != 0 + { + f.write_all(&buf[..x])?; + } + c.wait()?; + Ok(()) } fn main() -> std::io::Result<()> { |