Browse Source

Fix double trailing slash for section permalinks

Only happens for sections with lang != default
index-subcmd
Vincent Prouillet 5 years ago
parent
commit
260c413de4
1 changed files with 19 additions and 2 deletions
  1. +19
    -2
      components/library/src/content/section.rs

+ 19
- 2
components/library/src/content/section.rs View File

@@ -92,11 +92,11 @@ impl Section {
let (word_count, reading_time) = get_reading_analytics(&section.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/");
}
}

Loading…
Cancel
Save