1
+ use glob:: glob;
2
+ use std:: collections:: BTreeSet ;
1
3
use std:: fs:: read_to_string;
4
+ use std:: hash:: Hasher ;
5
+ use std:: path:: PathBuf ;
2
6
use std:: process:: Command ;
3
7
4
8
fn main ( ) {
@@ -27,9 +31,11 @@ fn main() {
27
31
28
32
let css_version = read_to_string ( "static/css/.pgml-bundle" ) . expect ( "failed to read .pgml-bundle" ) ;
29
33
let css_version = css_version. trim ( ) ;
34
+ println ! ( "cargo:rustc-env=CSS_VERSION={css_version}" ) ;
30
35
31
36
let js_version = read_to_string ( "static/js/.pgml-bundle" ) . expect ( "failed to read .pgml-bundle" ) ;
32
37
let js_version = js_version. trim ( ) ;
38
+ println ! ( "cargo:rustc-env=JS_VERSION={js_version}" ) ;
33
39
34
40
let status = Command :: new ( "cp" )
35
41
. arg ( "static/js/main.js" )
@@ -41,6 +47,15 @@ fn main() {
41
47
panic ! ( "failed to bundle main.js" ) ;
42
48
}
43
49
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 path in 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}" ) ;
46
61
}
0 commit comments