Browse Source

Add trailing slash to multilingual section path (#772)

index-subcmd
Katsutoshi Horie Vincent Prouillet 4 years ago
parent
commit
0238e34047
1 changed files with 22 additions and 1 deletions
  1. +22
    -1
      components/library/src/content/section.rs

+ 22
- 1
components/library/src/content/section.rs View File

@@ -113,7 +113,11 @@ impl Section {
section.reading_time = Some(reading_time);
let path = section.file.components.join("/");
if section.lang != config.default_language {
section.path = format!("{}/{}", section.lang, path);
if path.is_empty() {
section.path = format!("{}/", section.lang);
} else {
section.path = format!("{}/{}/", section.lang, path);
}
} else {
section.path = format!("{}/", path);
}
@@ -381,4 +385,21 @@ Bonjour le monde"#
assert_eq!(section.lang, "fr".to_string());
assert_eq!(section.permalink, "http://a-website.com/fr/");
}

#[test]
fn can_make_links_to_translated_subsections_with_trailing_slash() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false });
let content = r#"
+++
+++
Bonjour le monde"#
.to_string();
let res =
Section::parse(Path::new("content/subcontent/_index.fr.md"), &content, &config, &PathBuf::new());
assert!(res.is_ok());
let section = res.unwrap();
assert_eq!(section.lang, "fr".to_string());
assert_eq!(section.permalink, "http://a-website.com/fr/subcontent/");
}
}

Loading…
Cancel
Save