From 5fe45900631abdfec2f372feb2d09ca8bf68a3b1 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 10 Sep 2018 20:13:44 +0200 Subject: [PATCH] Default get_url to not add a trailing slash Closes #388 --- CHANGELOG.md | 1 + components/templates/src/global_fns.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f5a74..fb14e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Background colour is set fewer times when highlighting syntaxes - Link checker will not try to validate email links anymore - Load table and footnote markdown extensions in `markdown` filter +- `get_url` now defaults to not adding a trailing slash ## 0.4.2 (2018-09-03) diff --git a/components/templates/src/global_fns.rs b/components/templates/src/global_fns.rs index 52aa362..08b36fb 100644 --- a/components/templates/src/global_fns.rs +++ b/components/templates/src/global_fns.rs @@ -105,8 +105,8 @@ pub fn make_get_url(permalinks: HashMap, config: Config) -> Glob let trailing_slash = args .get("trailing_slash") - .map_or(true, |c| { - from_value::(c.clone()).unwrap_or(true) + .map_or(false, |c| { + from_value::(c.clone()).unwrap_or(false) }); let path = required_arg!( @@ -260,28 +260,28 @@ mod tests { let mut args = HashMap::new(); args.insert("path".to_string(), to_value("app.css").unwrap()); args.insert("cachebust".to_string(), to_value(true).unwrap()); - assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css/?t=1"); + assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css?t=1"); } #[test] - fn can_remove_trailing_slashes() { + fn can_add_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"); + args.insert("trailing_slash".to_string(), to_value(true).unwrap()); + assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css/"); } #[test] - fn can_remove_slashes_and_cachebust() { + fn can_add_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("trailing_slash".to_string(), to_value(true).unwrap()); args.insert("cachebust".to_string(), to_value(true).unwrap()); - assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css?t=1"); + assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css/?t=1"); } #[test] @@ -290,7 +290,7 @@ mod tests { let static_fn = make_get_url(HashMap::new(), config); let mut args = HashMap::new(); args.insert("path".to_string(), to_value("app.css").unwrap()); - assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css/"); + assert_eq!(static_fn(args).unwrap(), "http://a-website.com/app.css"); } #[test]