deps.rs/build.rs

35 lines
1.1 KiB
Rust
Raw Normal View History

use std::{env, fs, path::Path};
2018-01-29 07:34:22 +00:00
use sha1::{Digest, Sha1};
2018-01-29 07:34:22 +00:00
fn build_style() -> String {
2023-11-26 20:32:26 +00:00
grass::from_path(
"assets/styles/main.sass",
&grass::Options::default().style(grass::OutputStyle::Compressed),
)
.expect("failed to compile style sheet")
2018-01-29 07:34:22 +00:00
}
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
// compile the sass files into a single CSS file to be served and cached
let style = build_style();
let css_path = Path::new(&out_dir).join("style.css");
fs::write(css_path, style.as_bytes()).unwrap();
let hash_path = Path::new(&out_dir).join("style.css.sha1");
let digest = Sha1::digest(style.as_bytes());
2023-01-31 13:40:34 +00:00
fs::write(hash_path, format!("{digest:x}")).unwrap();
// hash and copy the JS file
let js_blob = fs::read("./assets/links.js").unwrap();
let js_path = Path::new(&out_dir).join("links.js");
fs::write(js_path, &js_blob).unwrap();
let js_hash_path = Path::new(&out_dir).join("links.js.sha1");
let js_digest = Sha1::digest(&js_blob);
2023-01-31 13:40:34 +00:00
fs::write(js_hash_path, format!("{js_digest:x}")).unwrap();
2018-01-29 07:34:22 +00:00
}