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:
parent
1ac39c2a6f
commit
e3b5f7f74f
@ -1,8 +0,0 @@
|
|||||||
use super::Heading;
|
|
||||||
use super::Section;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) enum DocumentElement {
|
|
||||||
Heading(Heading),
|
|
||||||
Section(Section),
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
#[derive(Debug)]
|
|
||||||
pub(crate) enum Element {}
|
|
@ -4,10 +4,10 @@ use std::path::PathBuf;
|
|||||||
use include_dir::include_dir;
|
use include_dir::include_dir;
|
||||||
use include_dir::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::config::Config;
|
||||||
use crate::error::CustomError;
|
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::DusterRenderer;
|
||||||
use crate::render::RendererIntegration;
|
use crate::render::RendererIntegration;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::blog_post::BlogPost;
|
|
||||||
use crate::cli::parameters::BuildArgs;
|
use crate::cli::parameters::BuildArgs;
|
||||||
use crate::command::build::render::SiteRenderer;
|
use crate::command::build::render::SiteRenderer;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::BlogPost;
|
||||||
|
|
||||||
pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
|
pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
|
||||||
let config = Config::load_from_file(args.config).await?;
|
let config = Config::load_from_file(args.config).await?;
|
||||||
|
@ -2,9 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::blog_post::Heading;
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::IHeading;
|
||||||
|
|
||||||
use super::RenderObject;
|
use super::RenderObject;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ impl RenderHeading {
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
output_directory: D,
|
output_directory: D,
|
||||||
output_file: F,
|
output_file: F,
|
||||||
heading: &Heading,
|
heading: &IHeading,
|
||||||
) -> Result<RenderHeading, CustomError> {
|
) -> Result<RenderHeading, CustomError> {
|
||||||
let title = heading
|
let title = heading
|
||||||
.title
|
.title
|
||||||
|
@ -2,9 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::blog_post::Object;
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::IObject;
|
||||||
|
|
||||||
use super::plain_text::RenderPlainText;
|
use super::plain_text::RenderPlainText;
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ impl RenderObject {
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
output_directory: D,
|
output_directory: D,
|
||||||
output_file: F,
|
output_file: F,
|
||||||
object: &Object,
|
object: &IObject,
|
||||||
) -> Result<RenderObject, CustomError> {
|
) -> Result<RenderObject, CustomError> {
|
||||||
match object {
|
match object {
|
||||||
Object::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new(
|
IObject::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new(
|
||||||
config,
|
config,
|
||||||
output_directory,
|
output_directory,
|
||||||
output_file,
|
output_file,
|
||||||
|
@ -2,9 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::blog_post::PlainText;
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::IPlainText;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
@ -16,7 +16,7 @@ impl RenderPlainText {
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
output_directory: D,
|
output_directory: D,
|
||||||
output_file: F,
|
output_file: F,
|
||||||
heading: &PlainText,
|
heading: &IPlainText,
|
||||||
) -> Result<RenderPlainText, CustomError> {
|
) -> Result<RenderPlainText, CustomError> {
|
||||||
Ok(RenderPlainText {})
|
Ok(RenderPlainText {})
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::blog_post::Section;
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::ISection;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
@ -16,7 +16,7 @@ impl RenderSection {
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
output_directory: D,
|
output_directory: D,
|
||||||
output_file: F,
|
output_file: F,
|
||||||
section: &Section,
|
section: &ISection,
|
||||||
) -> Result<RenderSection, CustomError> {
|
) -> Result<RenderSection, CustomError> {
|
||||||
Ok(RenderSection {})
|
Ok(RenderSection {})
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use crate::error::CustomError;
|
|||||||
|
|
||||||
use super::BlogPost;
|
use super::BlogPost;
|
||||||
use super::BlogPostPage;
|
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>>(
|
pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<Path>>(
|
||||||
config: &Config,
|
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() {
|
for child in page.children.iter() {
|
||||||
match child {
|
match child {
|
||||||
DocumentElement::Heading(heading) => {
|
IDocumentElement::Heading(heading) => {
|
||||||
children.push(RenderDocumentElement::Heading(RenderHeading::new(
|
children.push(RenderDocumentElement::Heading(RenderHeading::new(
|
||||||
config,
|
config,
|
||||||
output_directory,
|
output_directory,
|
||||||
@ -56,7 +56,7 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
|
|||||||
heading,
|
heading,
|
||||||
)?));
|
)?));
|
||||||
}
|
}
|
||||||
DocumentElement::Section(section) => {
|
IDocumentElement::Section(section) => {
|
||||||
children.push(RenderDocumentElement::Section(RenderSection::new(
|
children.push(RenderDocumentElement::Section(RenderSection::new(
|
||||||
config,
|
config,
|
||||||
output_directory,
|
output_directory,
|
@ -7,13 +7,13 @@ use walkdir::WalkDir;
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::BlogPostPage;
|
use super::BlogPostPage;
|
||||||
use super::DocumentElement;
|
use super::IDocumentElement;
|
||||||
|
|
||||||
#[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>,
|
pub(crate) children: Vec<IDocumentElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlogPost {
|
impl BlogPost {
|
8
src/intermediate/document_element.rs
Normal file
8
src/intermediate/document_element.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use super::IHeading;
|
||||||
|
use super::ISection;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) enum IDocumentElement {
|
||||||
|
Heading(IHeading),
|
||||||
|
Section(ISection),
|
||||||
|
}
|
2
src/intermediate/element.rs
Normal file
2
src/intermediate/element.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) enum IElement {}
|
@ -1,21 +1,21 @@
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::Object;
|
use super::IObject;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Heading {
|
pub(crate) struct IHeading {
|
||||||
pub(crate) level: organic::types::HeadlineLevel,
|
pub(crate) level: organic::types::HeadlineLevel,
|
||||||
pub(crate) title: Vec<Object>,
|
pub(crate) title: Vec<IObject>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Heading {
|
impl IHeading {
|
||||||
pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result<Heading, CustomError> {
|
pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result<IHeading, CustomError> {
|
||||||
let title = heading
|
let title = heading
|
||||||
.title
|
.title
|
||||||
.iter()
|
.iter()
|
||||||
.map(Object::new)
|
.map(IObject::new)
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
Ok(Heading {
|
Ok(IHeading {
|
||||||
title,
|
title,
|
||||||
level: heading.level,
|
level: heading.level,
|
||||||
})
|
})
|
@ -10,10 +10,10 @@ mod section;
|
|||||||
mod util;
|
mod util;
|
||||||
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 document_element::IDocumentElement;
|
||||||
pub(crate) use element::Element;
|
pub(crate) use element::IElement;
|
||||||
pub(crate) use heading::Heading;
|
pub(crate) use heading::IHeading;
|
||||||
pub(crate) use object::Object;
|
pub(crate) use object::IObject;
|
||||||
pub(crate) use page::BlogPostPage;
|
pub(crate) use page::BlogPostPage;
|
||||||
pub(crate) use plain_text::PlainText;
|
pub(crate) use plain_text::IPlainText;
|
||||||
pub(crate) use section::Section;
|
pub(crate) use section::ISection;
|
@ -1,14 +1,14 @@
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::plain_text::PlainText;
|
use super::plain_text::IPlainText;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum Object {
|
pub(crate) enum IObject {
|
||||||
PlainText(PlainText),
|
PlainText(IPlainText),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object {
|
impl IObject {
|
||||||
pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result<Object, CustomError> {
|
pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result<IObject, CustomError> {
|
||||||
match obj {
|
match obj {
|
||||||
organic::types::Object::Bold(_) => todo!(),
|
organic::types::Object::Bold(_) => todo!(),
|
||||||
organic::types::Object::Italic(_) => todo!(),
|
organic::types::Object::Italic(_) => todo!(),
|
||||||
@ -17,7 +17,7 @@ impl Object {
|
|||||||
organic::types::Object::Code(_) => todo!(),
|
organic::types::Object::Code(_) => todo!(),
|
||||||
organic::types::Object::Verbatim(_) => todo!(),
|
organic::types::Object::Verbatim(_) => todo!(),
|
||||||
organic::types::Object::PlainText(plain_text) => {
|
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::RegularLink(_) => todo!(),
|
||||||
organic::types::Object::RadioLink(_) => todo!(),
|
organic::types::Object::RadioLink(_) => todo!(),
|
@ -2,9 +2,9 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
use super::DocumentElement;
|
use super::IDocumentElement;
|
||||||
use super::Heading;
|
use super::IHeading;
|
||||||
use super::Section;
|
use super::ISection;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct BlogPostPage {
|
pub(crate) struct BlogPostPage {
|
||||||
@ -13,7 +13,7 @@ pub(crate) struct BlogPostPage {
|
|||||||
|
|
||||||
pub(crate) title: Option<String>,
|
pub(crate) title: Option<String>,
|
||||||
|
|
||||||
pub(crate) children: Vec<DocumentElement>,
|
pub(crate) children: Vec<IDocumentElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlogPostPage {
|
impl BlogPostPage {
|
||||||
@ -24,10 +24,10 @@ impl BlogPostPage {
|
|||||||
let path = path.into();
|
let path = path.into();
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
if let Some(section) = document.zeroth_section.as_ref() {
|
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() {
|
for heading in document.children.iter() {
|
||||||
children.push(DocumentElement::Heading(Heading::new(heading)?));
|
children.push(IDocumentElement::Heading(IHeading::new(heading)?));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(BlogPostPage {
|
Ok(BlogPostPage {
|
@ -1,16 +1,16 @@
|
|||||||
use crate::blog_post::util::coalesce_whitespace;
|
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
use crate::intermediate::util::coalesce_whitespace;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct PlainText {
|
pub(crate) struct IPlainText {
|
||||||
source: String,
|
source: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlainText {
|
impl IPlainText {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
plain_text: &organic::types::PlainText<'_>,
|
plain_text: &organic::types::PlainText<'_>,
|
||||||
) -> Result<PlainText, CustomError> {
|
) -> Result<IPlainText, CustomError> {
|
||||||
Ok(PlainText {
|
Ok(IPlainText {
|
||||||
source: coalesce_whitespace(plain_text.source).into_owned(),
|
source: coalesce_whitespace(plain_text.source).into_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Section {}
|
pub(crate) struct ISection {}
|
||||||
|
|
||||||
impl Section {
|
impl ISection {
|
||||||
pub(crate) fn new(section: &organic::types::Section<'_>) -> Result<Section, CustomError> {
|
pub(crate) fn new(section: &organic::types::Section<'_>) -> Result<ISection, CustomError> {
|
||||||
Ok(Section {})
|
Ok(ISection {})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,13 +7,13 @@ use self::cli::parameters::Commands;
|
|||||||
use self::command::build::build_site;
|
use self::command::build::build_site;
|
||||||
use self::command::init::init_writer_folder;
|
use self::command::init::init_writer_folder;
|
||||||
use self::error::CustomError;
|
use self::error::CustomError;
|
||||||
mod blog_post;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod command;
|
mod command;
|
||||||
mod config;
|
mod config;
|
||||||
mod error;
|
|
||||||
mod render;
|
|
||||||
mod context;
|
mod context;
|
||||||
|
mod error;
|
||||||
|
mod intermediate;
|
||||||
|
mod render;
|
||||||
|
|
||||||
fn main() -> Result<ExitCode, CustomError> {
|
fn main() -> Result<ExitCode, CustomError> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user