1+ use glob:: glob;
2+ use std:: collections:: BTreeSet ;
13use std:: fs:: read_to_string;
4+ use std:: hash:: Hasher ;
5+ use std:: path:: PathBuf ;
26use std:: process:: Command ;
37
48fn main ( ) {
@@ -27,9 +31,11 @@ fn main() {
2731
2832let css_version =read_to_string ( "static/css/.pgml-bundle" ) . expect ( "failed to read .pgml-bundle" ) ;
2933let css_version = css_version. trim ( ) ;
34+ println ! ( "cargo:rustc-env=CSS_VERSION={css_version}" ) ;
3035
3136let js_version =read_to_string ( "static/js/.pgml-bundle" ) . expect ( "failed to read .pgml-bundle" ) ;
3237let js_version = js_version. trim ( ) ;
38+ println ! ( "cargo:rustc-env=JS_VERSION={js_version}" ) ;
3339
3440let status =Command :: new ( "cp" )
3541. arg ( "static/js/main.js" )
@@ -41,6 +47,15 @@ fn main() {
4147panic ! ( "failed to bundle main.js" ) ;
4248}
4349
44- println ! ( "cargo:rustc-env=CSS_VERSION={css_version}" ) ;
45- println ! ( "cargo:rustc-env=JS_VERSION={js_version}" ) ;
50+ let files_paths =glob ( "./../pgml-cms/**/*.md" )
51+ . expect ( "Failed to read pgml-cms directory" )
52+ . map ( |p| p. unwrap ( ) )
53+ . collect :: < BTreeSet < PathBuf > > ( ) ;
54+ let mut hasher = std:: hash:: DefaultHasher :: new ( ) ;
55+ for pathin files_paths{
56+ let contents =read_to_string ( path. clone ( ) ) . expect ( "Error reading file" ) ;
57+ hasher. write ( & contents. into_bytes ( ) ) ;
58+ }
59+ let cms_hash = hasher. finish ( ) ;
60+ println ! ( "cargo:rustc-env=CMS_HASH={cms_hash}" ) ;
4661}