Don't use walkdir for getting the post directories.
We are only iterating a single level of depth anyway, so read_dir is enough.
This commit is contained in:
parent
a9fbb4cd63
commit
a0c5b2d852
@ -4,23 +4,14 @@ use crate::blog_post::BlogPost;
|
||||
use crate::cli::parameters::BuildArgs;
|
||||
use crate::config::Config;
|
||||
use crate::error::CustomError;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
|
||||
let config = Config::load_from_file(args.config).await?;
|
||||
let root_directory = config.get_root_directory().to_owned();
|
||||
let output_directory = get_output_directory(&config).await?;
|
||||
let post_directories = WalkDir::new(config.get_posts_directory())
|
||||
.into_iter()
|
||||
.filter(|e| match e {
|
||||
Ok(entry) if entry.depth() == 1 && entry.file_type().is_dir() => true,
|
||||
Ok(_) => false,
|
||||
Err(_) => true,
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let post_directories = get_post_directories(&config).await?;
|
||||
let load_jobs = post_directories
|
||||
.into_iter()
|
||||
.map(walkdir::DirEntry::into_path)
|
||||
.map(|path| tokio::spawn(BlogPost::load_blog_post(root_directory.clone(), path)));
|
||||
let mut blog_posts = Vec::new();
|
||||
for job in load_jobs {
|
||||
@ -48,3 +39,15 @@ async fn get_output_directory(config: &Config) -> Result<PathBuf, CustomError> {
|
||||
}
|
||||
Ok(output_directory)
|
||||
}
|
||||
|
||||
async fn get_post_directories(config: &Config) -> Result<Vec<PathBuf>, CustomError> {
|
||||
let mut ret = Vec::new();
|
||||
let mut entries = tokio::fs::read_dir(config.get_posts_directory()).await?;
|
||||
while let Some(entry) = entries.next_entry().await? {
|
||||
let file_type = entry.file_type().await?;
|
||||
if file_type.is_dir() {
|
||||
ret.push(entry.path());
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user