From 260c413de406dd176605eb1db3a75d17c5418e64 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 30 Jan 2019 20:01:10 +0100 Subject: [PATCH] Fix double trailing slash for section permalinks Only happens for sections with lang != default --- components/library/src/content/section.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index 2a7c4df8..9994b57e 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -92,11 +92,11 @@ impl Section { let (word_count, reading_time) = get_reading_analytics(§ion.raw_content); section.word_count = Some(word_count); section.reading_time = Some(reading_time); - let path = format!("{}/", section.file.components.join("/")); + let path = section.file.components.join("/"); if section.lang != config.default_language { section.path = format!("{}/{}", section.lang, path); } else { - section.path = path; + section.path = format!("{}/", path); } section.components = section .path @@ -318,4 +318,21 @@ Bonjour le monde"# assert_eq!(section.lang, "fr".to_string()); assert_eq!(section.permalink, "http://a-website.com/fr/hello/nested/"); } + + // https://zola.discourse.group/t/rfc-i18n/13/17?u=keats + #[test] + fn can_make_links_to_translated_sections_without_double_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/_index.fr.md"), &content, &config); + assert!(res.is_ok()); + let section = res.unwrap(); + assert_eq!(section.lang, "fr".to_string()); + assert_eq!(section.permalink, "http://a-website.com/fr/"); + } }