From b9f74b7eca18af4a6b2e29c3a35be48943e94efb Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 19 Oct 2024 16:25:54 -0400 Subject: [PATCH] Write the filter to find the highest folders containing org documents. --- src/command/build/runner.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index b9fe1b7..9b9b8c3 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -66,13 +66,27 @@ async fn filter_to_highest_folders_containing_org_files( entry: &DirEntry, ) -> Result { let file_type = entry.file_type().await?; + if !file_type.is_dir() { + return Ok(WalkAction::Halt); + } let mut entries = tokio::fs::read_dir(entry.path()).await?; - - todo!() + while let Some(entry) = entries.next_entry().await? { + let entry_type = entry.file_type().await?; + if !entry_type.is_file() { + continue; + } + match entry.path().extension().and_then(OsStr::to_str) { + Some("org") => { + return Ok(WalkAction::HaltAndCapture); + } + _ => {} + } + } + Ok(WalkAction::Recurse) } async fn get_post_directories(config: &Config) -> Result, CustomError> { - walk_fs( + let top_level_org_folders = walk_fs( config.get_posts_directory(), filter_to_highest_folders_containing_org_files, )