Make converstion to intermediate state async.

We are going to need to do things like call external tools for syntax highlighting so we are going to need async in there eventually.
This commit is contained in:
Tom Alexander 2023-10-27 15:55:19 -04:00
parent 4a6948cde7
commit f9377d7609
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 48 additions and 35 deletions

View File

@ -61,11 +61,14 @@ impl BlogPost {
let mut ret = Vec::new();
for (real_path, _contents, parsed_document) in parsed_org_files.iter() {
let relative_to_post_dir_path = real_path.strip_prefix(post_dir)?;
ret.push(BlogPostPage::new(
ret.push(
BlogPostPage::new(
relative_to_post_dir_path,
&mut registry,
parsed_document,
)?);
)
.await?,
);
}
ret
};

View File

@ -9,13 +9,13 @@ pub(crate) enum IElement {
}
impl IElement {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
elem: &organic::types::Element<'parse>,
) -> Result<IElement, CustomError> {
match elem {
organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner)?))
Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
}
organic::types::Element::PlainList(_) => todo!(),
organic::types::Element::CenterBlock(_) => todo!(),

View File

@ -10,15 +10,17 @@ pub(crate) struct IHeading {
}
impl IHeading {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
heading: &organic::types::Heading<'parse>,
) -> Result<IHeading, CustomError> {
let title = heading
.title
.iter()
.map(|obj| IObject::new(registry, obj))
.collect::<Result<Vec<_>, _>>()?;
let title = {
let mut ret = Vec::new();
for obj in heading.title.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IHeading {
title,
level: heading.level,

View File

@ -11,7 +11,7 @@ pub(crate) enum IObject {
}
impl IObject {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
obj: &organic::types::Object<'parse>,
) -> Result<IObject, CustomError> {
@ -23,7 +23,7 @@ impl IObject {
organic::types::Object::Code(_) => todo!(),
organic::types::Object::Verbatim(_) => todo!(),
organic::types::Object::PlainText(inner) => {
Ok(IObject::PlainText(IPlainText::new(registry, inner)?))
Ok(IObject::PlainText(IPlainText::new(registry, inner).await?))
}
organic::types::Object::RegularLink(_) => todo!(),
organic::types::Object::RadioLink(_) => todo!(),
@ -41,7 +41,7 @@ impl IObject {
organic::types::Object::InlineSourceBlock(_) => todo!(),
organic::types::Object::LineBreak(_) => todo!(),
organic::types::Object::Target(inner) => {
Ok(IObject::Target(ITarget::new(registry, inner)?))
Ok(IObject::Target(ITarget::new(registry, inner).await?))
}
organic::types::Object::StatisticsCookie(_) => todo!(),
organic::types::Object::Subscript(_) => todo!(),

View File

@ -18,7 +18,7 @@ pub(crate) struct BlogPostPage {
}
impl BlogPostPage {
pub(crate) fn new<'parse, P: Into<PathBuf>>(
pub(crate) async fn new<'parse, P: Into<PathBuf>>(
path: P,
registry: &mut Registry<'parse>,
document: &organic::types::Document<'parse>,
@ -26,10 +26,14 @@ impl BlogPostPage {
let path = path.into();
let mut children = Vec::new();
if let Some(section) = document.zeroth_section.as_ref() {
children.push(IDocumentElement::Section(ISection::new(registry, section)?));
children.push(IDocumentElement::Section(
ISection::new(registry, section).await?,
));
}
for heading in document.children.iter() {
children.push(IDocumentElement::Heading(IHeading::new(registry, heading)?));
children.push(IDocumentElement::Heading(
IHeading::new(registry, heading).await?,
));
}
Ok(BlogPostPage {

View File

@ -9,15 +9,17 @@ pub(crate) struct IParagraph {
}
impl IParagraph {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
paragraph: &organic::types::Paragraph<'parse>,
) -> Result<IParagraph, CustomError> {
let children = paragraph
.children
.iter()
.map(|obj| IObject::new(registry, obj))
.collect::<Result<Vec<_>, _>>()?;
let children = {
let mut ret = Vec::new();
for obj in paragraph.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IParagraph { children })
}

View File

@ -9,9 +9,9 @@ pub(crate) struct IPlainText {
}
impl IPlainText {
pub(crate) fn new(
registry: &mut Registry<'_>,
plain_text: &organic::types::PlainText<'_>,
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
plain_text: &organic::types::PlainText<'parse>,
) -> Result<IPlainText, CustomError> {
Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(),

View File

@ -9,15 +9,17 @@ pub(crate) struct ISection {
}
impl ISection {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
section: &organic::types::Section<'parse>,
) -> Result<ISection, CustomError> {
let children = section
.children
.iter()
.map(|obj| IElement::new(registry, obj))
.collect::<Result<Vec<_>, _>>()?;
let children = {
let mut ret = Vec::new();
for elem in section.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
Ok(ISection { children })
}

View File

@ -10,7 +10,7 @@ pub(crate) struct ITarget {
}
impl ITarget {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
target: &organic::types::Target<'parse>,
) -> Result<ITarget, CustomError> {