From 379850fe3d0e1f349f320fb2abffbb45d4918d4f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 19 Oct 2024 16:55:38 -0400 Subject: [PATCH] Use the deep path as the post id. --- src/command/build/runner.rs | 11 ++++++++--- src/intermediate/blog_post.rs | 15 +++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index f184be9..20b57b5 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -103,10 +103,15 @@ async fn get_post_directories(config: &Config) -> Result, CustomErr async fn load_blog_posts(config: &Config) -> Result, CustomError> { let root_directory = config.get_root_directory().to_owned(); + let posts_directory = config.get_posts_directory(); let post_directories = get_post_directories(config).await?; - let load_jobs = post_directories - .into_iter() - .map(|path| tokio::spawn(BlogPost::load_blog_post(root_directory.clone(), path))); + let load_jobs = post_directories.into_iter().map(|path| { + tokio::spawn(BlogPost::load_blog_post( + root_directory.clone(), + posts_directory.clone(), + path, + )) + }); let mut blog_posts = Vec::new(); for job in load_jobs { blog_posts.push(job.await??); diff --git a/src/intermediate/blog_post.rs b/src/intermediate/blog_post.rs index da3a374..01f8d08 100644 --- a/src/intermediate/blog_post.rs +++ b/src/intermediate/blog_post.rs @@ -20,14 +20,17 @@ pub(crate) struct BlogPost { } impl BlogPost { - pub(crate) async fn load_blog_post, R: AsRef>( + pub(crate) async fn load_blog_post, R: AsRef, S: AsRef>( root_dir: R, + posts_dir: S, 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."); + async fn inner( + _root_dir: &Path, + posts_dir: &Path, + post_dir: &Path, + ) -> Result { + let post_id = post_dir.strip_prefix(posts_dir)?.as_os_str(); let org_files = { let mut ret = Vec::new(); @@ -80,7 +83,7 @@ impl BlogPost { pages, }) } - inner(root_dir.as_ref(), post_dir.as_ref()).await + inner(root_dir.as_ref(), posts_dir.as_ref(), post_dir.as_ref()).await } /// Get the date for a blog post.