Fix double trailing slash for section permalinks

Only happens for sections with lang != default
This commit is contained in:
Vincent Prouillet 2019-01-30 20:01:10 +01:00
parent 5082e0f15a
commit 260c413de4

View file

@ -92,11 +92,11 @@ impl Section {
let (word_count, reading_time) = get_reading_analytics(&section.raw_content); let (word_count, reading_time) = get_reading_analytics(&section.raw_content);
section.word_count = Some(word_count); section.word_count = Some(word_count);
section.reading_time = Some(reading_time); 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 { if section.lang != config.default_language {
section.path = format!("{}/{}", section.lang, path); section.path = format!("{}/{}", section.lang, path);
} else { } else {
section.path = path; section.path = format!("{}/", path);
} }
section.components = section section.components = section
.path .path
@ -318,4 +318,21 @@ Bonjour le monde"#
assert_eq!(section.lang, "fr".to_string()); assert_eq!(section.lang, "fr".to_string());
assert_eq!(section.permalink, "http://a-website.com/fr/hello/nested/"); 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/");
}
} }