Use the deep path as the post id.

This commit is contained in:
Tom Alexander
2024-10-19 16:55:38 -04:00
parent 8ab69e480e
commit 379850fe3d
2 changed files with 17 additions and 9 deletions

View File

@@ -20,14 +20,17 @@ pub(crate) struct BlogPost {
}
impl BlogPost {
pub(crate) async fn load_blog_post<P: AsRef<Path>, R: AsRef<Path>>(
pub(crate) async fn load_blog_post<P: AsRef<Path>, R: AsRef<Path>, S: AsRef<Path>>(
root_dir: R,
posts_dir: S,
post_dir: P,
) -> Result<BlogPost, CustomError> {
async fn inner(_root_dir: &Path, post_dir: &Path) -> Result<BlogPost, CustomError> {
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<BlogPost, CustomError> {
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.