Standardize the construction of intermediate BlogPostPage.

This commit is contained in:
Tom Alexander
2023-12-19 17:09:11 -05:00
parent 261fe8a1a2
commit 4bb1f9983a
27 changed files with 405 additions and 248 deletions

View File

@@ -4,10 +4,28 @@ use crate::error::CustomError;
use super::footnote_definition::IRealFootnoteDefinition;
use super::macros::intermediate;
use super::IDocumentElement;
use super::IHeading;
use super::ISection;
use super::RefRegistry;
#[derive(Debug)]
pub(crate) struct BlogPostPageInput<'b, 'parse> {
path: PathBuf,
document: &'b organic::types::Document<'parse>,
}
impl<'b, 'parse> BlogPostPageInput<'b, 'parse> {
pub(crate) fn new<P: Into<PathBuf>>(
path: P,
document: &'b organic::types::Document<'parse>,
) -> BlogPostPageInput<'b, 'parse> {
BlogPostPageInput {
path: path.into(),
document,
}
}
}
#[derive(Debug)]
pub(crate) struct BlogPostPage {
@@ -23,21 +41,19 @@ pub(crate) struct BlogPostPage {
pub(crate) footnotes: Vec<IRealFootnoteDefinition>,
}
impl BlogPostPage {
// TODO: Move path into the registry so I can give this a standard interface like the others.
pub(crate) async fn new<'a, 'b, 'parse, P: Into<PathBuf>>(
path: P,
registry: RefRegistry<'b, 'parse>,
document: &'b organic::types::Document<'parse>,
) -> Result<BlogPostPage, CustomError> {
let path = path.into();
intermediate!(
BlogPostPage,
BlogPostPageInput<'orig, 'parse>,
original,
registry,
{
let mut children = Vec::new();
if let Some(section) = document.zeroth_section.as_ref() {
if let Some(section) = original.document.zeroth_section.as_ref() {
children.push(IDocumentElement::Section(
ISection::new(registry.clone(), section).await?,
));
}
for heading in document.children.iter() {
for heading in original.document.children.iter() {
children.push(IDocumentElement::Heading(
IHeading::new(registry.clone(), heading).await?,
));
@@ -60,14 +76,16 @@ impl BlogPostPage {
};
Ok(BlogPostPage {
path,
title: get_title(&document),
date: get_date(&document),
path: original.path,
title: get_title(original.document),
date: get_date(original.document),
children,
footnotes,
})
}
);
impl BlogPostPage {
/// Get the output path relative to the post directory.
pub(crate) fn get_output_path(&self) -> PathBuf {
let mut ret = self.path.clone();