Convert intermediate objects into render objects.

This commit is contained in:
Tom Alexander 2023-10-27 12:47:12 -04:00
parent 4c59011389
commit 744d3e50fb
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 77 additions and 3 deletions

View File

@ -5,10 +5,14 @@ use std::path::PathBuf;
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::DocumentElement;
pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
@ -39,11 +43,38 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
output_file.strip_prefix(output_directory)?,
)?;
let children = {
let mut children = Vec::new();
for child in page.children.iter() {
match child {
DocumentElement::Heading(heading) => {
children.push(RenderDocumentElement::Heading(RenderHeading::new(
config,
output_directory,
output_file,
heading,
)?));
}
DocumentElement::Section(section) => {
children.push(RenderDocumentElement::Section(RenderSection::new(
config,
output_directory,
output_file,
section,
)?));
}
}
}
children
};
let ret = RenderBlogPostPage::new(
global_settings,
page.title.clone(),
Some(link_to_blog_post),
Vec::new(),
children,
);
Ok(ret)
}

View File

@ -4,8 +4,8 @@ use super::Object;
#[derive(Debug)]
pub(crate) struct Heading {
title: Vec<Object>,
level: organic::types::HeadlineLevel,
pub(crate) level: organic::types::HeadlineLevel,
pub(crate) title: Vec<Object>,
}
impl Heading {

View File

@ -1,10 +1,36 @@
use std::path::Path;
use serde::Serialize;
use crate::blog_post::Heading;
use crate::config::Config;
use crate::error::CustomError;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "heading")]
pub(crate) struct RenderHeading {
level: organic::types::HeadlineLevel,
title: Vec<RenderObject>,
}
impl RenderHeading {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
heading: &Heading,
) -> Result<RenderHeading, CustomError> {
let title = heading
.title
.iter()
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
.collect::<Result<Vec<_>, _>>()?;
Ok(RenderHeading {
level: heading.level,
title,
})
}
}

View File

@ -1,5 +1,22 @@
use std::path::Path;
use serde::Serialize;
use crate::blog_post::Object;
use crate::config::Config;
use crate::error::CustomError;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderObject {}
impl RenderObject {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
section: &Object,
) -> Result<RenderObject, CustomError> {
todo!()
}
}