Add tests for slug strategy in filenames with dates

This commit is contained in:
Vincent Prouillet 2021-02-22 20:39:31 +01:00
parent 2bbd3bd424
commit 7fc7ef4720
2 changed files with 49 additions and 1 deletions

View file

@ -683,6 +683,26 @@ Hello world
assert_eq!(page.slug, "hello"); assert_eq!(page.slug, "hello");
} }
// https://github.com/getzola/zola/pull/1323#issuecomment-779401063
#[test]
fn can_get_date_from_short_date_in_filename_respects_slugification_strategy() {
let mut config = Config::default();
config.slugify.paths = SlugifyStrategy::Off;
let content = r#"
+++
+++
Hello world
<!-- more -->"#
.to_string();
let res =
Page::parse(Path::new("2018-10-08_ こんにちは.md"), &content, &config, &PathBuf::new());
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.meta.date, Some("2018-10-08".to_string()));
assert_eq!(page.slug, " こんにちは");
}
#[test] #[test]
fn can_get_date_from_full_rfc3339_date_in_filename() { fn can_get_date_from_full_rfc3339_date_in_filename() {
let config = Config::default(); let config = Config::default();
@ -705,6 +725,30 @@ Hello world
assert_eq!(page.slug, "hello"); assert_eq!(page.slug, "hello");
} }
// https://github.com/getzola/zola/pull/1323#issuecomment-779401063
#[test]
fn can_get_date_from_full_rfc3339_date_in_filename_respects_slugification_strategy() {
let mut config = Config::default();
config.slugify.paths = SlugifyStrategy::Off;
let content = r#"
+++
+++
Hello world
<!-- more -->"#
.to_string();
let res = Page::parse(
Path::new("2018-10-02T15:00:00Z- こんにちは.md"),
&content,
&config,
&PathBuf::new(),
);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.meta.date, Some("2018-10-02T15:00:00Z".to_string()));
assert_eq!(page.slug, " こんにちは");
}
#[test] #[test]
fn frontmatter_date_override_filename_date() { fn frontmatter_date_override_filename_date() {
let config = Config::default(); let config = Config::default();

View file

@ -205,7 +205,11 @@ impl TeraFn for GetFileHash {
let f = match open_file(&self.search_paths, &path) { let f = match open_file(&self.search_paths, &path) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
return Err(format!("File {} could not be open: {} (searched in {:?})", path, e, self.search_paths).into()); return Err(format!(
"File {} could not be open: {} (searched in {:?})",
path, e, self.search_paths
)
.into());
} }
}; };