From ba893ae8e1a068f9777c53a7070480795d2815b8 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Thu, 30 Mar 2023 23:04:48 -0400 Subject: [PATCH] wip: Finish up Site::render --- src/site.rs | 35 +++++++++++++++++++++++++++++++++-- src/site/page.rs | 23 +++++++++++++++++++++-- src/site/post.rs | 23 +++++++++++++++++++++-- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/site.rs b/src/site.rs index b1ac127..e91353f 100644 --- a/src/site.rs +++ b/src/site.rs @@ -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, }, /// 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, + }, } diff --git a/src/site/page.rs b/src/site/page.rs index 60e20ae..b7bba05 100644 --- a/src/site/page.rs +++ b/src/site/page.rs @@ -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, + output_dir: impl AsRef, + ) -> 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"); + } } diff --git a/src/site/post.rs b/src/site/post.rs index 5ae18bc..20726ac 100644 --- a/src/site/post.rs +++ b/src/site/post.rs @@ -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, + output_dir: impl AsRef, + ) -> 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"); + } }