Add children to heading.

This commit is contained in:
Tom Alexander
2023-10-27 18:59:40 -04:00
parent bd982fb62d
commit c279bad13a
62 changed files with 406 additions and 203 deletions

View File

@@ -6,13 +6,10 @@ use crate::config::Config;
use crate::context::GlobalSettings;
use crate::context::RenderBlogPostPage;
use crate::context::RenderDocumentElement;
use crate::context::RenderHeading;
use crate::context::RenderSection;
use crate::error::CustomError;
use super::BlogPost;
use super::BlogPostPage;
use super::IDocumentElement;
pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
@@ -47,24 +44,12 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
let mut children = Vec::new();
for child in page.children.iter() {
match child {
IDocumentElement::Heading(heading) => {
children.push(RenderDocumentElement::Heading(RenderHeading::new(
config,
output_directory,
output_file,
heading,
)?));
}
IDocumentElement::Section(section) => {
children.push(RenderDocumentElement::Section(RenderSection::new(
config,
output_directory,
output_file,
section,
)?));
}
}
children.push(RenderDocumentElement::new(
config,
output_directory,
output_file,
child,
)?);
}
children

View File

@@ -1,8 +1,31 @@
use crate::error::CustomError;
use super::registry::Registry;
use super::IHeading;
use super::ISection;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
pub(crate) enum IDocumentElement {
Heading(IHeading),
Section(ISection),
}
impl IDocumentElement {
pub(crate) fn new<'parse, 'b>(
registry: &'b mut Registry<'parse>,
original: &'b organic::types::DocumentElement<'parse>,
) -> BoxFuture<'b, Result<IDocumentElement, CustomError>> {
async move {
match original {
organic::types::DocumentElement::Heading(inner) => Ok(IDocumentElement::Heading(
IHeading::new(registry, inner).await?,
)),
organic::types::DocumentElement::Section(inner) => Ok(IDocumentElement::Section(
ISection::new(registry, inner).await?,
)),
}
}
.boxed()
}
}

View File

@@ -1,12 +1,14 @@
use crate::error::CustomError;
use super::registry::Registry;
use super::IDocumentElement;
use super::IObject;
#[derive(Debug)]
pub(crate) struct IHeading {
pub(crate) level: organic::types::HeadlineLevel,
pub(crate) title: Vec<IObject>,
pub(crate) children: Vec<IDocumentElement>,
}
impl IHeading {
@@ -21,9 +23,17 @@ impl IHeading {
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in heading.children.iter() {
ret.push(IDocumentElement::new(registry, obj).await?);
}
ret
};
Ok(IHeading {
title,
level: heading.level,
children,
})
}
}