Use the deep path as the post id.
This commit is contained in:
parent
8ab69e480e
commit
379850fe3d
@ -103,10 +103,15 @@ async fn get_post_directories(config: &Config) -> Result<Vec<PathBuf>, CustomErr
|
|||||||
|
|
||||||
async fn load_blog_posts(config: &Config) -> Result<Vec<BlogPost>, CustomError> {
|
async fn load_blog_posts(config: &Config) -> Result<Vec<BlogPost>, CustomError> {
|
||||||
let root_directory = config.get_root_directory().to_owned();
|
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 post_directories = get_post_directories(config).await?;
|
||||||
let load_jobs = post_directories
|
let load_jobs = post_directories.into_iter().map(|path| {
|
||||||
.into_iter()
|
tokio::spawn(BlogPost::load_blog_post(
|
||||||
.map(|path| tokio::spawn(BlogPost::load_blog_post(root_directory.clone(), path)));
|
root_directory.clone(),
|
||||||
|
posts_directory.clone(),
|
||||||
|
path,
|
||||||
|
))
|
||||||
|
});
|
||||||
let mut blog_posts = Vec::new();
|
let mut blog_posts = Vec::new();
|
||||||
for job in load_jobs {
|
for job in load_jobs {
|
||||||
blog_posts.push(job.await??);
|
blog_posts.push(job.await??);
|
||||||
|
@ -20,14 +20,17 @@ pub(crate) struct BlogPost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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,
|
root_dir: R,
|
||||||
|
posts_dir: S,
|
||||||
post_dir: P,
|
post_dir: P,
|
||||||
) -> Result<BlogPost, CustomError> {
|
) -> Result<BlogPost, CustomError> {
|
||||||
async fn inner(_root_dir: &Path, post_dir: &Path) -> Result<BlogPost, CustomError> {
|
async fn inner(
|
||||||
let post_id = post_dir
|
_root_dir: &Path,
|
||||||
.file_name()
|
posts_dir: &Path,
|
||||||
.expect("The post directory should have a name.");
|
post_dir: &Path,
|
||||||
|
) -> Result<BlogPost, CustomError> {
|
||||||
|
let post_id = post_dir.strip_prefix(posts_dir)?.as_os_str();
|
||||||
|
|
||||||
let org_files = {
|
let org_files = {
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
@ -80,7 +83,7 @@ impl BlogPost {
|
|||||||
pages,
|
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.
|
/// Get the date for a blog post.
|
||||||
|
Loading…
Reference in New Issue
Block a user