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/"); + } }