wip: Finish up Site::render

This commit is contained in:
Nathan McCarty 2023-03-30 23:04:48 -04:00
parent 07b6708d30
commit ba893ae8e1
No known key found for this signature in database
3 changed files with 75 additions and 6 deletions

View File

@ -336,7 +336,25 @@ impl Site {
warn!(?from_path, ?to_path, "To path had no parent?");
}
}
todo!("Site::render stub")
// Render the pages
for (path, page) in &self.pages {
page.render(self, site_dir, output_dir)
.context(RenderSnafu {
path_from: &path,
path_to: &output_dir,
document: "Page",
})?;
}
// Render the posts
for (path, post) in &self.posts {
post.render(self, site_dir, output_dir)
.context(RenderSnafu {
path_from: &path,
path_to: &output_dir,
document: "Post",
})?;
}
Ok(())
}
}
/// Error encountered interacting with a [`Site`]
@ -454,7 +472,7 @@ pub enum SiteError {
configs: Vec<PathBuf>,
},
/// Error copying a static file
#[snafu(display("Errory copying {:?} to {:?}", path_from, path_to))]
#[snafu(display("Error copying {:?} to {:?}", path_from, path_to))]
StaticFileCopy {
/// The path being copied from
path_from: PathBuf,
@ -463,4 +481,17 @@ pub enum SiteError {
/// The underlying error
source: std::io::Error,
},
/// Failed to render out a document
#[snafu(display("Failed rendering a {document} {:?} -> {:?}", path_from, path_to))]
Render {
/// The path we tried to write the document from
path_from: PathBuf,
/// The path we tried to write the document to
path_to: PathBuf,
/// The type of the document
document: &'static str,
/// The underlying error
#[snafu(source(from(SiteError, Box::new)))]
source: Box<SiteError>,
},
}

View File

@ -15,8 +15,8 @@ use tracing::{debug, info, info_span, warn};
use super::{
ConfigReadSnafu, ConfigReifySnafu, CreateDirectorySnafu, DuplicateConfigsSnafu,
EnumerateDirectorySnafu, ExistanceCheckSnafu, NotADirectorySnafu, SiteError, WriteConfigSnafu,
WritePageStubSnafu,
EnumerateDirectorySnafu, ExistanceCheckSnafu, NotADirectorySnafu, Site, SiteError,
WriteConfigSnafu, WritePageStubSnafu,
};
/// Representation of the configuration for a page
@ -206,4 +206,23 @@ impl Page {
file: djot_path,
})
}
/// Renders the page in the given input directory to the given output path
///
/// # Errors
///
/// Will return an error if the djot conversion fails, or if any I/O errors occur during writing.
pub fn render(
&self,
site: &Site,
site_dir: impl AsRef<Path>,
output_dir: impl AsRef<Path>,
) -> Result<(), SiteError> {
// Get dirs and setup logging
let site_dir = site_dir.as_ref();
let output_dir = output_dir.as_ref();
let span = info_span!("Page::render", ?site_dir, ?output_dir);
let _enter = span.enter();
todo!("Page::render");
}
}

View File

@ -17,8 +17,8 @@ use tracing::{debug, info, info_span, span, warn, Level};
use super::{
ConfigReadSnafu, ConfigReifySnafu, CreateDirectorySnafu, DuplicateConfigsSnafu,
EnumerateDirectorySnafu, ExistanceCheckSnafu, NotADirectorySnafu, SiteError, WriteConfigSnafu,
WritePostStubSnafu,
EnumerateDirectorySnafu, ExistanceCheckSnafu, NotADirectorySnafu, Site, SiteError,
WriteConfigSnafu, WritePostStubSnafu,
};
/// Representation of the configuration for a post
@ -226,4 +226,23 @@ impl Post {
file: djot_path,
})
}
/// Renders the post in the given input directory to the given output path
///
/// # Errors
///
/// Will return an error if the djot conversion fails, or if any I/O errors occur during writing.
pub fn render(
&self,
site: &Site,
site_dir: impl AsRef<Path>,
output_dir: impl AsRef<Path>,
) -> Result<(), SiteError> {
// Get dirs and setup logging
let site_dir = site_dir.as_ref();
let output_dir = output_dir.as_ref();
let span = info_span!("Post::render", ?site_dir, ?output_dir);
let _enter = span.enter();
todo!("Post::render");
}
}