Starting to introduce a BlogPostPage struct.
Blog posts are going to be constructed of multiple documents each forming their own page. This will allow me to link to supporting documents without having to promote them to their own pages.
This commit is contained in:
parent
199621b6f1
commit
e543a5db74
@ -2,7 +2,5 @@ use super::render_context::RenderBlogPost;
|
||||
use super::BlogPost;
|
||||
|
||||
pub(crate) fn convert_blog_post_to_render_context(post: &BlogPost) -> RenderBlogPost {
|
||||
RenderBlogPost {
|
||||
id: post.id.clone(),
|
||||
}
|
||||
RenderBlogPost::new(post.id.clone())
|
||||
}
|
||||
|
@ -6,9 +6,12 @@ use walkdir::WalkDir;
|
||||
|
||||
use crate::error::CustomError;
|
||||
|
||||
use super::BlogPostPage;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct BlogPost {
|
||||
pub(crate) id: String,
|
||||
pages: Vec<BlogPostPage>,
|
||||
}
|
||||
|
||||
impl BlogPost {
|
||||
@ -39,8 +42,21 @@ impl BlogPost {
|
||||
ret
|
||||
};
|
||||
|
||||
let pages = {
|
||||
let mut ret = Vec::new();
|
||||
for (real_path, _contents, parsed_document) in parsed_org_files {
|
||||
let relative_to_post_dir_path = real_path.strip_prefix(post_dir)?;
|
||||
ret.push(BlogPostPage::new(
|
||||
relative_to_post_dir_path,
|
||||
parsed_document,
|
||||
)?);
|
||||
}
|
||||
ret
|
||||
};
|
||||
|
||||
Ok(BlogPost {
|
||||
id: post_id.to_string_lossy().into_owned(),
|
||||
pages,
|
||||
})
|
||||
}
|
||||
inner(root_dir.as_ref(), post_dir.as_ref()).await
|
||||
|
@ -1,5 +1,7 @@
|
||||
mod convert;
|
||||
mod definition;
|
||||
mod page;
|
||||
mod render_context;
|
||||
pub(crate) use convert::convert_blog_post_to_render_context;
|
||||
pub(crate) use definition::BlogPost;
|
||||
pub(crate) use page::BlogPostPage;
|
||||
|
24
src/blog_post/page.rs
Normal file
24
src/blog_post/page.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::CustomError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct BlogPostPage {
|
||||
/// Relative path from the root of the blog post.
|
||||
path: PathBuf,
|
||||
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl BlogPostPage {
|
||||
pub(crate) fn new<P: Into<PathBuf>>(
|
||||
path: P,
|
||||
document: organic::types::Document<'_>,
|
||||
) -> Result<BlogPostPage, CustomError> {
|
||||
let path = path.into();
|
||||
Ok(BlogPostPage {
|
||||
path,
|
||||
title: "".to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
@ -4,5 +4,11 @@ use serde::Serialize;
|
||||
#[serde(tag = "type")]
|
||||
#[serde(rename = "blog_post")]
|
||||
pub(crate) struct RenderBlogPost {
|
||||
pub(crate) id: String,
|
||||
id: String,
|
||||
}
|
||||
|
||||
impl RenderBlogPost {
|
||||
pub(crate) fn new(id: String) -> RenderBlogPost {
|
||||
RenderBlogPost { id }
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ pub(crate) enum CustomError {
|
||||
FromUtf8(FromUtf8Error),
|
||||
DusterCompile(duster::renderer::CompileError),
|
||||
DusterRender(duster::renderer::RenderError),
|
||||
PathStripPrefix(std::path::StripPrefixError),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for CustomError {
|
||||
@ -81,3 +82,9 @@ impl From<duster::renderer::RenderError> for CustomError {
|
||||
CustomError::DusterRender(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::path::StripPrefixError> for CustomError {
|
||||
fn from(value: std::path::StripPrefixError) -> Self {
|
||||
CustomError::PathStripPrefix(value)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user