From 284ef6a30175aa096f2cb8434cd7598533bee5e6 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 17 Apr 2025 19:00:50 +0200 Subject: [PATCH 1/3] front_matter: fix traversal of content directory The previous approach that only looked for markdown files in content/ and content/inside-rust/ stopped working when we started using Zola's feature of colocating a blog post with its assets. In those cases, the markdown file might be located at content//index.md. --- Cargo.lock | 1 + front_matter/Cargo.toml | 3 +++ front_matter/src/lib.rs | 15 +++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 550c21469..fb89ce2e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,7 @@ dependencies = [ "eyre", "serde", "toml", + "walkdir", ] [[package]] diff --git a/front_matter/Cargo.toml b/front_matter/Cargo.toml index 93120b784..4337313e7 100644 --- a/front_matter/Cargo.toml +++ b/front_matter/Cargo.toml @@ -7,3 +7,6 @@ edition = "2024" eyre = "=0.6.12" serde = { version = "=1.0.219", features = ["derive"] } toml = "=0.8.20" + +[dev-dependencies] +walkdir = "2.5.0" diff --git a/front_matter/src/lib.rs b/front_matter/src/lib.rs index 9a4798efe..3d4c4ff4d 100644 --- a/front_matter/src/lib.rs +++ b/front_matter/src/lib.rs @@ -253,11 +253,14 @@ The post {post} has abnormal front matter. } fn all_posts() -> impl Iterator { - let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".."); - fs::read_dir(repo_root.join("content")) - .unwrap() - .chain(fs::read_dir(repo_root.join("content/inside-rust")).unwrap()) - .map(|p| p.unwrap().path()) - .filter(|p| p.is_file() && p.file_name() != Some("_index.md".as_ref())) + walkdir::WalkDir::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../content")) + .into_iter() + .filter_map(|e| e.ok().map(|e| e.into_path())) + .filter(|p| { + p.is_file() + && p.extension() == Some("md".as_ref()) + && p.file_name() != Some("_index.md".as_ref()) + && p.file_name() != Some("latest.md".as_ref()) + }) } } From 3fdd2ef1160558ec1dc473e64e13821550e2d7b5 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 17 Apr 2025 19:12:56 +0200 Subject: [PATCH 2/3] front_matter: improve error messages --- front_matter/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/front_matter/src/lib.rs b/front_matter/src/lib.rs index 3d4c4ff4d..aba00fd10 100644 --- a/front_matter/src/lib.rs +++ b/front_matter/src/lib.rs @@ -175,9 +175,11 @@ mod tests { .contains("content/inside-rust/"); let content = fs::read_to_string(&post).unwrap(); - let (front_matter, rest) = parse(&content).unwrap(); + let (front_matter, rest) = parse(&content).unwrap_or_else(|err| { + panic!("failed to parse {:?}: {err}", post.display()); + }); let normalized = normalize(&front_matter, slug, inside_rust).unwrap_or_else(|err| { - panic!("failed to normalize {:?}: {err}", post.file_name().unwrap()); + panic!("failed to normalize {:?}: {err}", post.display()); }); if front_matter != normalized { From 42888510e0477379b05e28e23851624220bc9a72 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Thu, 17 Apr 2025 19:16:05 +0200 Subject: [PATCH 3/3] Add missing release aliases These were previously missed because the front matter validation tests did not descend into the individual directories of posts with colocated assets. --- content/Rust-1.12/index.md | 5 ++++- content/Rust-1.13/index.md | 5 ++++- content/Rust-1.30.0/index.md | 5 ++++- content/Rust-1.60.0/index.md | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/content/Rust-1.12/index.md b/content/Rust-1.12/index.md index 4870fff60..549e16abd 100644 --- a/content/Rust-1.12/index.md +++ b/content/Rust-1.12/index.md @@ -2,7 +2,10 @@ path = "2016/09/29/Rust-1.12" title = "Announcing Rust 1.12" authors = ["The Rust Core Team"] -aliases = ["2016/09/29/Rust-1.12.html"] +aliases = [ + "2016/09/29/Rust-1.12.html", + "releases/1.12.0", +] [extra] release = true diff --git a/content/Rust-1.13/index.md b/content/Rust-1.13/index.md index 42afc59cb..ea9175e04 100644 --- a/content/Rust-1.13/index.md +++ b/content/Rust-1.13/index.md @@ -2,7 +2,10 @@ path = "2016/11/10/Rust-1.13" title = "Announcing Rust 1.13" authors = ["The Rust Core Team"] -aliases = ["2016/11/10/Rust-1.13.html"] +aliases = [ + "2016/11/10/Rust-1.13.html", + "releases/1.13.0", +] [extra] release = true diff --git a/content/Rust-1.30.0/index.md b/content/Rust-1.30.0/index.md index 5d89e50ec..daaae637b 100644 --- a/content/Rust-1.30.0/index.md +++ b/content/Rust-1.30.0/index.md @@ -2,7 +2,10 @@ path = "2018/10/25/Rust-1.30.0" title = "Announcing Rust 1.30" authors = ["The Rust Core Team"] -aliases = ["2018/10/25/Rust-1.30.0.html"] +aliases = [ + "2018/10/25/Rust-1.30.0.html", + "releases/1.30.0", +] [extra] release = true diff --git a/content/Rust-1.60.0/index.md b/content/Rust-1.60.0/index.md index 63b3dc8d3..8485c37ed 100644 --- a/content/Rust-1.60.0/index.md +++ b/content/Rust-1.60.0/index.md @@ -2,7 +2,10 @@ path = "2022/04/07/Rust-1.60.0" title = "Announcing Rust 1.60.0" authors = ["The Rust Release Team"] -aliases = ["2022/04/07/Rust-1.60.0.html"] +aliases = [ + "2022/04/07/Rust-1.60.0.html", + "releases/1.60.0", +] [extra] release = true