mirror of
https://github.com/Noratrieb/does-it-build.git
synced 2026-01-14 18:35:01 +01:00
make it blazingly fast with caching of css and js
This commit is contained in:
parent
f539a3c45c
commit
d15a746558
8 changed files with 77 additions and 18 deletions
32
build.rs
32
build.rs
|
|
@ -1,6 +1,29 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use sha2::Digest;
|
||||
|
||||
fn main() {
|
||||
// Always rerun.
|
||||
|
||||
let index_css = include_str!("static/index.css");
|
||||
let index_js = include_str!("static/index.js");
|
||||
|
||||
let index_css_name = get_file_ref("css", index_css);
|
||||
let index_js_name = get_file_ref("js", index_js);
|
||||
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
|
||||
std::fs::write(
|
||||
out_dir.join("revs.rs"),
|
||||
format!(
|
||||
r#"
|
||||
pub const INDEX_CSS_NAME: &str = "{index_css_name}";
|
||||
pub const INDEX_JS_NAME: &str = "{index_js_name}";
|
||||
"#
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let version = if let Ok(commit) = try_get_commit() {
|
||||
match has_no_changes() {
|
||||
Ok(true) => commit,
|
||||
|
|
@ -20,6 +43,15 @@ fn main() {
|
|||
println!("cargo:rustc-env=GIT_COMMIT_SHORT={version_short}");
|
||||
}
|
||||
|
||||
fn get_file_ref(ext: &str, content: &str) -> String {
|
||||
let mut hash = sha2::Sha256::new();
|
||||
hash.update(content);
|
||||
let digest = hash.finalize();
|
||||
let rev = bs58::encode(digest).into_string();
|
||||
let rev = &rev[..16];
|
||||
format!("/{rev}.{ext}")
|
||||
}
|
||||
|
||||
fn try_get_commit() -> color_eyre::Result<String> {
|
||||
if let Ok(overridden) = std::env::var("DOES_IT_BUILD_OVERRIDE_VERSION") {
|
||||
return Ok(overridden);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue