diff --git a/components/templates/src/global_fns/files.rs b/components/templates/src/global_fns/files.rs index 914883e4..3c33d027 100644 --- a/components/templates/src/global_fns/files.rs +++ b/components/templates/src/global_fns/files.rs @@ -2,13 +2,12 @@ use std::collections::HashMap; use std::path::PathBuf; use std::{fs, io, result}; +use crate::global_fns::helpers::search_for_file; use base64::encode as encode_b64; +use config::Config; use sha2::{digest, Sha256, Sha384, Sha512}; use tera::{from_value, to_value, Function as TeraFn, Result, Value}; -use config::Config; use utils::site::resolve_internal_link; -use crate::global_fns::helpers::search_for_file; - fn compute_file_hash( mut file: fs::File, diff --git a/components/templates/src/global_fns/images.rs b/components/templates/src/global_fns/images.rs index 1058c568..5773d755 100644 --- a/components/templates/src/global_fns/images.rs +++ b/components/templates/src/global_fns/images.rs @@ -145,6 +145,7 @@ mod tests { use std::fs::{copy, create_dir_all}; use config::Config; + use std::path::Path; use std::sync::{Arc, Mutex}; use tempfile::{tempdir, TempDir}; use tera::{to_value, Function}; @@ -177,9 +178,11 @@ mod tests { // 1. resizing an image in static args.insert("path".to_string(), to_value("static/gutenberg.jpg").unwrap()); let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); + let static_path = Path::new("static").join("processed_images"); + assert_eq!( data["static_path"], - to_value("static/processed_images/e49f5bd23ec5007c00.jpg").unwrap() + to_value(&format!("{}", static_path.join("e49f5bd23ec5007c00.jpg").display())).unwrap() ); assert_eq!( data["url"], @@ -191,7 +194,7 @@ mod tests { let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); assert_eq!( data["static_path"], - to_value("static/processed_images/32454a1e0243976c00.jpg").unwrap() + to_value(&format!("{}", static_path.join("32454a1e0243976c00.jpg").display())).unwrap() ); assert_eq!( data["url"], @@ -203,7 +206,7 @@ mod tests { let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); assert_eq!( data["static_path"], - to_value("static/processed_images/074e171855ee541800.jpg").unwrap() + to_value(&format!("{}", static_path.join("074e171855ee541800.jpg").display())).unwrap() ); assert_eq!( data["url"], @@ -215,7 +218,7 @@ mod tests { let data = static_fn.call(&args).unwrap().as_object().unwrap().clone(); assert_eq!( data["static_path"], - to_value("static/processed_images/c8aaba7b0593a60b00.jpg").unwrap() + to_value(&format!("{}", static_path.join("c8aaba7b0593a60b00.jpg").display())).unwrap() ); assert_eq!( data["url"], diff --git a/components/templates/src/global_fns/load_data.rs b/components/templates/src/global_fns/load_data.rs index 55695fac..7992b695 100644 --- a/components/templates/src/global_fns/load_data.rs +++ b/components/templates/src/global_fns/load_data.rs @@ -610,21 +610,22 @@ mod tests { let static_fn = LoadData::new(dir.path().to_path_buf()); let mut args = HashMap::new(); + let val = if cfg!(windows) { ".hello {}\r\n" } else { ".hello {}\n" }; // 1. relative path in `static` args.insert("path".to_string(), to_value("static/test.css").unwrap()); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); - assert_eq!(data, ".hello {}\n"); + assert_eq!(data, val); // 2. relative path in `content` args.insert("path".to_string(), to_value("content/test.css").unwrap()); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); - assert_eq!(data, ".hello {}\n"); + assert_eq!(data, val); // 3. path starting with @/ args.insert("path".to_string(), to_value("@/test.css").unwrap()); let data = static_fn.call(&args).unwrap().as_str().unwrap().to_string(); - assert_eq!(data, ".hello {}\n"); + assert_eq!(data, val); // 4. absolute path does not work args.insert("path".to_string(), to_value("/test.css").unwrap());