Skip to content

Commit 284ef6a

Browse files
committed
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/<slug>/index.md.
1 parent cbeb36c commit 284ef6a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front_matter/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ edition = "2024"
77
eyre = "=0.6.12"
88
serde = { version = "=1.0.219", features = ["derive"] }
99
toml = "=0.8.20"
10+
11+
[dev-dependencies]
12+
walkdir = "2.5.0"

front_matter/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,14 @@ The post {post} has abnormal front matter.
253253
}
254254

255255
fn all_posts() -> impl Iterator<Item = PathBuf> {
256-
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
257-
fs::read_dir(repo_root.join("content"))
258-
.unwrap()
259-
.chain(fs::read_dir(repo_root.join("content/inside-rust")).unwrap())
260-
.map(|p| p.unwrap().path())
261-
.filter(|p| p.is_file() && p.file_name() != Some("_index.md".as_ref()))
256+
walkdir::WalkDir::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../content"))
257+
.into_iter()
258+
.filter_map(|e| e.ok().map(|e| e.into_path()))
259+
.filter(|p| {
260+
p.is_file()
261+
&& p.extension() == Some("md".as_ref())
262+
&& p.file_name() != Some("_index.md".as_ref())
263+
&& p.file_name() != Some("latest.md".as_ref())
264+
})
262265
}
263266
}

0 commit comments

Comments
 (0)