Rename blog_post module to intermediate.

This module is mostly the intermediate representation of the AST, so the renaming is to make that more clear. The three forms are parsed => intermediate => render.

Parsed comes from Organic and is a direct translation of the org-mode text.

Intermediate converts the parsed data into owned values and does any calculations that are needed on the data (for example: assigning numbers to footnotes.)

Render takes intermediate and translates it into the format expected by the dust templates. The processing in this step should be minimal since all the logic should be in the intermediate step.
This commit is contained in:
Tom Alexander 2023-10-27 13:05:34 -04:00
parent 1ac39c2a6f
commit e3b5f7f74f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
20 changed files with 64 additions and 64 deletions

View File

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

View File

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

View File

@ -4,10 +4,10 @@ use std::path::PathBuf;
use include_dir::include_dir;
use include_dir::Dir;
use crate::blog_post::convert_blog_post_page_to_render_context;
use crate::blog_post::BlogPost;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::convert_blog_post_page_to_render_context;
use crate::intermediate::BlogPost;
use crate::render::DusterRenderer;
use crate::render::RendererIntegration;

View File

@ -1,10 +1,10 @@
use std::path::PathBuf;
use crate::blog_post::BlogPost;
use crate::cli::parameters::BuildArgs;
use crate::command::build::render::SiteRenderer;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::BlogPost;
pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
let config = Config::load_from_file(args.config).await?;

View File

@ -2,9 +2,9 @@ use std::path::Path;
use serde::Serialize;
use crate::blog_post::Heading;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IHeading;
use super::RenderObject;
@ -21,7 +21,7 @@ impl RenderHeading {
config: &Config,
output_directory: D,
output_file: F,
heading: &Heading,
heading: &IHeading,
) -> Result<RenderHeading, CustomError> {
let title = heading
.title

View File

@ -2,9 +2,9 @@ use std::path::Path;
use serde::Serialize;
use crate::blog_post::Object;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IObject;
use super::plain_text::RenderPlainText;
@ -19,10 +19,10 @@ impl RenderObject {
config: &Config,
output_directory: D,
output_file: F,
object: &Object,
object: &IObject,
) -> Result<RenderObject, CustomError> {
match object {
Object::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new(
IObject::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new(
config,
output_directory,
output_file,

View File

@ -2,9 +2,9 @@ use std::path::Path;
use serde::Serialize;
use crate::blog_post::PlainText;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IPlainText;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
@ -16,7 +16,7 @@ impl RenderPlainText {
config: &Config,
output_directory: D,
output_file: F,
heading: &PlainText,
heading: &IPlainText,
) -> Result<RenderPlainText, CustomError> {
Ok(RenderPlainText {})
}

View File

@ -2,9 +2,9 @@ use std::path::Path;
use serde::Serialize;
use crate::blog_post::Section;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::ISection;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
@ -16,7 +16,7 @@ impl RenderSection {
config: &Config,
output_directory: D,
output_file: F,
section: &Section,
section: &ISection,
) -> Result<RenderSection, CustomError> {
Ok(RenderSection {})
}

View File

@ -12,7 +12,7 @@ use crate::error::CustomError;
use super::BlogPost;
use super::BlogPostPage;
use super::DocumentElement;
use super::IDocumentElement;
pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
@ -48,7 +48,7 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
for child in page.children.iter() {
match child {
DocumentElement::Heading(heading) => {
IDocumentElement::Heading(heading) => {
children.push(RenderDocumentElement::Heading(RenderHeading::new(
config,
output_directory,
@ -56,7 +56,7 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
heading,
)?));
}
DocumentElement::Section(section) => {
IDocumentElement::Section(section) => {
children.push(RenderDocumentElement::Section(RenderSection::new(
config,
output_directory,

View File

@ -7,13 +7,13 @@ use walkdir::WalkDir;
use crate::error::CustomError;
use super::BlogPostPage;
use super::DocumentElement;
use super::IDocumentElement;
#[derive(Debug)]
pub(crate) struct BlogPost {
pub(crate) id: String,
pub(crate) pages: Vec<BlogPostPage>,
pub(crate) children: Vec<DocumentElement>,
pub(crate) children: Vec<IDocumentElement>,
}
impl BlogPost {

View File

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

View File

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

View File

@ -1,21 +1,21 @@
use crate::error::CustomError;
use super::Object;
use super::IObject;
#[derive(Debug)]
pub(crate) struct Heading {
pub(crate) struct IHeading {
pub(crate) level: organic::types::HeadlineLevel,
pub(crate) title: Vec<Object>,
pub(crate) title: Vec<IObject>,
}
impl Heading {
pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result<Heading, CustomError> {
impl IHeading {
pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result<IHeading, CustomError> {
let title = heading
.title
.iter()
.map(Object::new)
.map(IObject::new)
.collect::<Result<Vec<_>, _>>()?;
Ok(Heading {
Ok(IHeading {
title,
level: heading.level,
})

View File

@ -10,10 +10,10 @@ mod section;
mod util;
pub(crate) use convert::convert_blog_post_page_to_render_context;
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 document_element::IDocumentElement;
pub(crate) use element::IElement;
pub(crate) use heading::IHeading;
pub(crate) use object::IObject;
pub(crate) use page::BlogPostPage;
pub(crate) use plain_text::PlainText;
pub(crate) use section::Section;
pub(crate) use plain_text::IPlainText;
pub(crate) use section::ISection;

View File

@ -1,14 +1,14 @@
use crate::error::CustomError;
use super::plain_text::PlainText;
use super::plain_text::IPlainText;
#[derive(Debug)]
pub(crate) enum Object {
PlainText(PlainText),
pub(crate) enum IObject {
PlainText(IPlainText),
}
impl Object {
pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result<Object, CustomError> {
impl IObject {
pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result<IObject, CustomError> {
match obj {
organic::types::Object::Bold(_) => todo!(),
organic::types::Object::Italic(_) => todo!(),
@ -17,7 +17,7 @@ impl Object {
organic::types::Object::Code(_) => todo!(),
organic::types::Object::Verbatim(_) => todo!(),
organic::types::Object::PlainText(plain_text) => {
Ok(Object::PlainText(PlainText::new(plain_text)?))
Ok(IObject::PlainText(IPlainText::new(plain_text)?))
}
organic::types::Object::RegularLink(_) => todo!(),
organic::types::Object::RadioLink(_) => todo!(),

View File

@ -2,9 +2,9 @@ use std::path::PathBuf;
use crate::error::CustomError;
use super::DocumentElement;
use super::Heading;
use super::Section;
use super::IDocumentElement;
use super::IHeading;
use super::ISection;
#[derive(Debug)]
pub(crate) struct BlogPostPage {
@ -13,7 +13,7 @@ pub(crate) struct BlogPostPage {
pub(crate) title: Option<String>,
pub(crate) children: Vec<DocumentElement>,
pub(crate) children: Vec<IDocumentElement>,
}
impl BlogPostPage {
@ -24,10 +24,10 @@ impl BlogPostPage {
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)?));
children.push(IDocumentElement::Section(ISection::new(section)?));
}
for heading in document.children.iter() {
children.push(DocumentElement::Heading(Heading::new(heading)?));
children.push(IDocumentElement::Heading(IHeading::new(heading)?));
}
Ok(BlogPostPage {

View File

@ -1,16 +1,16 @@
use crate::blog_post::util::coalesce_whitespace;
use crate::error::CustomError;
use crate::intermediate::util::coalesce_whitespace;
#[derive(Debug)]
pub(crate) struct PlainText {
pub(crate) struct IPlainText {
source: String,
}
impl PlainText {
impl IPlainText {
pub(crate) fn new(
plain_text: &organic::types::PlainText<'_>,
) -> Result<PlainText, CustomError> {
Ok(PlainText {
) -> Result<IPlainText, CustomError> {
Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(),
})
}

View File

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

View File

@ -7,13 +7,13 @@ use self::cli::parameters::Commands;
use self::command::build::build_site;
use self::command::init::init_writer_folder;
use self::error::CustomError;
mod blog_post;
mod cli;
mod command;
mod config;
mod error;
mod render;
mod context;
mod error;
mod intermediate;
mod render;
fn main() -> Result<ExitCode, CustomError> {
let rt = tokio::runtime::Runtime::new()?;