Introduce the corresponding non-render types.

This commit is contained in:
Tom Alexander 2023-10-24 00:36:08 -04:00
parent 3b472a9e96
commit 2b7a19a1d4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
19 changed files with 91 additions and 10 deletions

View File

@ -4,8 +4,8 @@ use std::path::PathBuf;
use crate::config::Config; use crate::config::Config;
use crate::error::CustomError; use crate::error::CustomError;
use crate::types::GlobalSettings; use crate::context::GlobalSettings;
use crate::types::RenderBlogPostPage; use crate::context::RenderBlogPostPage;
use super::BlogPost; use super::BlogPost;
use super::BlogPostPage; use super::BlogPostPage;

View File

@ -7,11 +7,13 @@ use walkdir::WalkDir;
use crate::error::CustomError; use crate::error::CustomError;
use super::BlogPostPage; use super::BlogPostPage;
use super::DocumentElement;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct BlogPost { pub(crate) struct BlogPost {
pub(crate) id: String, pub(crate) id: String,
pub(crate) pages: Vec<BlogPostPage>, pub(crate) pages: Vec<BlogPostPage>,
pub(crate) children: Vec<DocumentElement>,
} }
impl BlogPost { impl BlogPost {
@ -57,6 +59,7 @@ impl BlogPost {
Ok(BlogPost { Ok(BlogPost {
id: post_id.to_string_lossy().into_owned(), id: post_id.to_string_lossy().into_owned(),
pages, pages,
children: Vec::new(),
}) })
} }
inner(root_dir.as_ref(), post_dir.as_ref()).await inner(root_dir.as_ref(), post_dir.as_ref()).await

View File

@ -0,0 +1,8 @@
use super::Heading;
use super::Section;
#[derive(Debug)]
pub(crate) enum DocumentElement {
Heading(Heading),
Section(Section),
}

2
src/blog_post/element.rs Normal file
View File

@ -0,0 +1,2 @@
#[derive(Debug)]
pub(crate) enum Element {}

10
src/blog_post/heading.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::error::CustomError;
#[derive(Debug)]
pub(crate) struct Heading {}
impl Heading {
pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result<Heading, CustomError> {
todo!()
}
}

View File

@ -1,6 +1,16 @@
mod convert; mod convert;
mod definition; mod definition;
mod document_element;
mod element;
mod heading;
mod object;
mod page; mod page;
mod section;
pub(crate) use convert::convert_blog_post_page_to_render_context; pub(crate) use convert::convert_blog_post_page_to_render_context;
pub(crate) use definition::BlogPost; pub(crate) use definition::BlogPost;
pub(crate) use document_element::DocumentElement;
pub(crate) use element::Element;
pub(crate) use heading::Heading;
pub(crate) use object::Object;
pub(crate) use page::BlogPostPage; pub(crate) use page::BlogPostPage;
pub(crate) use section::Section;

2
src/blog_post/object.rs Normal file
View File

@ -0,0 +1,2 @@
#[derive(Debug)]
pub(crate) enum Object {}

View File

@ -2,12 +2,18 @@ use std::path::PathBuf;
use crate::error::CustomError; use crate::error::CustomError;
use super::DocumentElement;
use super::Heading;
use super::Section;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct BlogPostPage { pub(crate) struct BlogPostPage {
/// Relative path from the root of the blog post. /// Relative path from the root of the blog post.
pub(crate) path: PathBuf, pub(crate) path: PathBuf,
pub(crate) title: Option<String>, pub(crate) title: Option<String>,
pub(crate) children: Vec<DocumentElement>,
} }
impl BlogPostPage { impl BlogPostPage {
@ -16,9 +22,18 @@ impl BlogPostPage {
document: organic::types::Document<'_>, document: organic::types::Document<'_>,
) -> Result<BlogPostPage, CustomError> { ) -> Result<BlogPostPage, CustomError> {
let path = path.into(); let path = path.into();
let mut children = Vec::new();
if let Some(section) = document.zeroth_section.as_ref() {
children.push(DocumentElement::Section(Section::new(section)?));
}
for heading in document.children.iter() {
children.push(DocumentElement::Heading(Heading::new(heading)?));
}
Ok(BlogPostPage { Ok(BlogPostPage {
path, path,
title: get_title(&document), title: get_title(&document),
children,
}) })
} }

10
src/blog_post/section.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::error::CustomError;
#[derive(Debug)]
pub(crate) struct Section {}
impl Section {
pub(crate) fn new(section: &organic::types::Section<'_>) -> Result<Section, CustomError> {
todo!()
}
}

View File

@ -1,6 +1,10 @@
use serde::Serialize; use serde::Serialize;
use super::RenderObject;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
#[serde(rename = "heading")] #[serde(rename = "heading")]
pub(crate) struct RenderHeading {} pub(crate) struct RenderHeading {
title: Vec<RenderObject>,
}

23
src/context/section.rs Normal file
View File

@ -0,0 +1,23 @@
use std::path::Path;
use serde::Serialize;
use crate::blog_post::Section;
use crate::config::Config;
use crate::error::CustomError;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "section")]
pub(crate) struct RenderSection {}
impl RenderSection {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
section: &Section,
) -> Result<RenderSection, CustomError> {
todo!()
}
}

View File

@ -13,7 +13,7 @@ mod command;
mod config; mod config;
mod error; mod error;
mod render; mod render;
mod types; mod context;
fn main() -> Result<ExitCode, CustomError> { fn main() -> Result<ExitCode, CustomError> {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;

View File

@ -1,6 +0,0 @@
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "section")]
pub(crate) struct RenderSection {}