|
|
@@ -59,7 +59,13 @@ pub fn make_get_url(permalinks: HashMap<String, String>, config: Config) -> Glob |
|
|
|
.map_or(false, |c| { |
|
|
|
from_value::<bool>(c.clone()).unwrap_or(false) |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let trailing_slash = args |
|
|
|
.get("trailing_slash") |
|
|
|
.map_or(true, |c| { |
|
|
|
from_value::<bool>(c.clone()).unwrap_or(true) |
|
|
|
}); |
|
|
|
|
|
|
|
match args.get("path") { |
|
|
|
Some(val) => match from_value::<String>(val.clone()) { |
|
|
|
Ok(v) => { |
|
|
@@ -72,6 +78,10 @@ pub fn make_get_url(permalinks: HashMap<String, String>, config: Config) -> Glob |
|
|
|
} else { |
|
|
|
// anything else |
|
|
|
let mut permalink = config.make_permalink(&v); |
|
|
|
if !trailing_slash && permalink.ends_with("/") { |
|
|
|
permalink.pop(); // Removes the slash |
|
|
|
} |
|
|
|
|
|
|
|
if cachebust { |
|
|
|
permalink = format!("{}?t={}", permalink, config.build_timestamp.unwrap()); |
|
|
|
} |
|
|
@@ -105,6 +115,27 @@ mod tests { |
|
|
|
args.insert("cachebust".to_string(), to_value(true).unwrap()); |
|
|
|
assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css/?t=1"); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn can_remove_trailing_slashes() { |
|
|
|
let config = Config::default(); |
|
|
|
let static_fn = make_get_url(HashMap::new(), config); |
|
|
|
let mut args = HashMap::new(); |
|
|
|
args.insert("path".to_string(), to_value("app.css").unwrap()); |
|
|
|
args.insert("trailing_slash".to_string(), to_value(false).unwrap()); |
|
|
|
assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css"); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn can_remove_slashes_and_cachebust() { |
|
|
|
let config = Config::default(); |
|
|
|
let static_fn = make_get_url(HashMap::new(), config); |
|
|
|
let mut args = HashMap::new(); |
|
|
|
args.insert("path".to_string(), to_value("app.css").unwrap()); |
|
|
|
args.insert("trailing_slash".to_string(), to_value(false).unwrap()); |
|
|
|
args.insert("cachebust".to_string(), to_value(true).unwrap()); |
|
|
|
assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css?t=1"); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn can_link_to_some_static_file() { |
|
|
|