diff --git a/src/command/build/mod.rs b/src/command/build/mod.rs index b1b161e..6b8fd66 100644 --- a/src/command/build/mod.rs +++ b/src/command/build/mod.rs @@ -1,5 +1,6 @@ mod render; mod runner; mod stylesheet; +mod walk_fs; pub(crate) use runner::build_site; diff --git a/src/command/build/walk_fs.rs b/src/command/build/walk_fs.rs new file mode 100644 index 0000000..7b427ee --- /dev/null +++ b/src/command/build/walk_fs.rs @@ -0,0 +1,26 @@ +use std::ops::AsyncFn; +use std::path::Path; + +use tokio::fs::DirEntry; + +use crate::error::CustomError; + +pub(crate) async fn walk_fs, F: AsyncFn(&DirEntry) -> Result>( + root: P, + predicate: F, +) -> Result, CustomError> { + let mut ret = Vec::new(); + let mut entries = tokio::fs::read_dir(root).await?; + while let Some(entry) = entries.next_entry().await? { + let file_type = entry.file_type().await?; + if file_type.is_dir() { + let child_entries = walk_fs(entry.path(), &predicate).await?; + ret.extend(child_entries); + } + if predicate(&entry).await? { + ret.push(entry); + } + } + + Ok(ret) +} diff --git a/src/main.rs b/src/main.rs index 7feed97..09fb643 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![feature(let_chains)] +#![feature(async_closure)] use std::process::ExitCode; use clap::Parser;