From 0238e34047899b99cdb16efaae6a04b9723ab4e8 Mon Sep 17 00:00:00 2001 From: Katsutoshi Horie Date: Tue, 13 Aug 2019 01:59:04 +0900 Subject: [PATCH] Add trailing slash to multilingual section path (#772) --- components/library/src/content/section.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index 534d1588..bbcedfa2 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -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/"); + } }