Browse Source

Default get_url to not add a trailing slash

Closes #388
index-subcmd
Vincent Prouillet 6 years ago
parent
commit
5fe4590063
2 changed files with 11 additions and 10 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +10
    -10
      components/templates/src/global_fns.rs

+ 1
- 0
CHANGELOG.md View File

@@ -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)



+ 10
- 10
components/templates/src/global_fns.rs View File

@@ -105,8 +105,8 @@ pub fn make_get_url(permalinks: HashMap<String, String>, config: Config) -> Glob

let trailing_slash = args
.get("trailing_slash")
.map_or(true, |c| {
from_value::<bool>(c.clone()).unwrap_or(true)
.map_or(false, |c| {
from_value::<bool>(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]


Loading…
Cancel
Save