-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (26 loc) · 954 Bytes
/
Copy pathbuild.rs
File metadata and controls
30 lines (26 loc) · 954 Bytes
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
27
28
29
30
use html_minifier::HTMLMinifier;
use std::{env, fs, io, path::PathBuf};
const INSTANCE_NOTICE_MARKER: &[u8] = b"__DISASTER_ALERT_INSTANCE_NOTICE__";
fn main() -> io::Result<()> {
println!("cargo:rerun-if-changed=web/index.html");
let source = fs::read("web/index.html")?;
if source
.windows(INSTANCE_NOTICE_MARKER.len())
.filter(|window| *window == INSTANCE_NOTICE_MARKER)
.count()
!= 1
{
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"web/index.html must contain exactly one instance notice marker",
));
}
let mut minifier = HTMLMinifier::new();
minifier.digest(source).map_err(io::Error::other)?;
let output = PathBuf::from(
env::var_os("OUT_DIR")
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Cargo did not set OUT_DIR"))?,
)
.join("index.min.html");
fs::write(output, minifier.get_html())
}