From 07e4209048a8d8a62c755fb298e21a481aedf625 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 22 Oct 2023 13:50:11 -0400 Subject: [PATCH] Setting the post id based on the folder name. --- src/blog_post/definition.rs | 6 +++++- src/command/build/runner.rs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/blog_post/definition.rs b/src/blog_post/definition.rs index 5ef06b0..5179858 100644 --- a/src/blog_post/definition.rs +++ b/src/blog_post/definition.rs @@ -17,6 +17,10 @@ impl BlogPost { post_dir: P, ) -> Result { async fn inner(root_dir: &Path, post_dir: &Path) -> Result { + let post_id = post_dir + .file_name() + .expect("The post directory should have a name."); + let org_files = { let mut ret = Vec::new(); let org_files_iter = get_org_files(post_dir)?; @@ -36,7 +40,7 @@ impl BlogPost { }; Ok(BlogPost { - id: "foo".to_owned(), + id: post_id.to_string_lossy().into_owned(), }) } inner(root_dir.as_ref(), post_dir.as_ref()).await diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index 38fb73e..9ca5f4a 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -19,5 +19,10 @@ pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> { .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 { + blog_posts.push(job.await??); + } + println!("{:?}", blog_posts); Ok(()) }