Add test for #1566

Closes #1566
This commit is contained in:
Vincent Prouillet 2023-02-12 00:27:42 +01:00 committed by Vincent Prouillet
parent 05ab07bff0
commit 0b31fc10d2
2 changed files with 35 additions and 124 deletions

126
Cargo.lock generated
View file

@ -96,17 +96,6 @@ dependencies = [
"serde_json",
]
[[package]]
name = "async-trait"
version = "0.1.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -721,25 +710,6 @@ dependencies = [
"syn",
]
[[package]]
name = "deadpool"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "421fe0f90f2ab22016f32a9881be5134fdd71c65298917084b0c7477cbc3856e"
dependencies = [
"async-trait",
"deadpool-runtime",
"num_cpus",
"retain_mut",
"tokio",
]
[[package]]
name = "deadpool-runtime"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaa37046cc0f6c3cc6090fbdbf73ef0b8ef4cfcc37f6befc0020f63e8cf121e1"
[[package]]
name = "derive_more"
version = "0.99.17"
@ -1087,21 +1057,6 @@ dependencies = [
"new_debug_unreachable",
]
[[package]]
name = "futures"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.26"
@ -1109,7 +1064,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@ -1118,34 +1072,12 @@ version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
[[package]]
name = "futures-executor"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531"
[[package]]
name = "futures-macro"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.26"
@ -1164,11 +1096,8 @@ version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
@ -2020,7 +1949,7 @@ dependencies = [
"config",
"errors",
"libs",
"mockito 0.31.1",
"mockito",
"utils",
]
@ -2258,28 +2187,6 @@ dependencies = [
"similar",
]
[[package]]
name = "mockito"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae57f68b2bfc165b12f6c61e0de614cba4f97913b382f61cc40df80287fcce0a"
dependencies = [
"assert-json-diff",
"async-trait",
"colored",
"deadpool",
"futures",
"hyper",
"lazy_static",
"log",
"rand 0.8.5",
"regex",
"serde_json",
"serde_urlencoded",
"similar",
"tokio",
]
[[package]]
name = "mutate_once"
version = "0.1.1"
@ -3157,12 +3064,6 @@ dependencies = [
"winreg",
]
[[package]]
name = "retain_mut"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0"
[[package]]
name = "ring"
version = "0.16.20"
@ -3436,15 +3337,6 @@ dependencies = [
"digest 0.10.6",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "simd-adler32"
version = "0.3.4"
@ -3666,7 +3558,7 @@ dependencies = [
"imageproc",
"libs",
"markdown",
"mockito 0.32.0",
"mockito",
"tempfile",
"utils",
]
@ -3855,25 +3747,11 @@ dependencies = [
"memchr",
"mio 0.8.5",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.42.0",
]
[[package]]
name = "tokio-macros"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"

View file

@ -146,6 +146,7 @@ impl Page {
slugify_paths(&file_path_for_slug, config.slugify.paths)
}
};
println!("page.slug = {:?}", page.slug);
page.path = if let Some(ref p) = page.meta.path {
let path = p.trim();
@ -701,6 +702,38 @@ And here's another. [^3]
assert_eq!(page.assets[0].file_name().unwrap().to_str(), Some("graph.jpg"));
}
// https://github.com/getzola/zola/issues/1566
#[test]
fn colocated_page_with_slug_and_date_in_path() {
let tmp_dir = tempdir().expect("create temp dir");
let path = tmp_dir.path();
create_dir(&path.join("content")).expect("create content temp dir");
let articles_path = path.join("content").join("articles");
create_dir(&articles_path).expect("create posts temp dir");
let config = Config::default();
// first a non-colocated one
let file_path = articles_path.join("2021-07-29-sample-article-1.md");
let mut f = File::create(&file_path).unwrap();
f.write_all(b"+++\nslug=\"hey\"\n+++\n").unwrap();
let res = Page::from_file(&file_path, &config, path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.path, "/articles/hey/");
// then a colocated one, it should still work
let dir_path = articles_path.join("2021-07-29-sample-article-2.md");
create_dir(&dir_path).expect("create posts temp dir");
let mut f = File::create(&dir_path.join("index.md")).unwrap();
f.write_all(b"+++\nslug=\"ho\"\n+++\n").unwrap();
let res = Page::from_file(&dir_path.join("index.md"), &config, path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.path, "/articles/ho/");
}
#[test]
fn can_get_date_from_short_date_in_filename() {
let config = Config::default();