Switch over to using the render context in render calls.

This commit is contained in:
Tom Alexander
2023-12-19 15:42:37 -05:00
parent cb3278aba5
commit add267d616
67 changed files with 699 additions and 1197 deletions

View File

@@ -3,93 +3,8 @@ use std::path::Path;
use std::path::PathBuf;
use crate::config::Config;
use crate::context::GlobalSettings;
use crate::context::PageHeader;
use crate::context::RenderBlogPostPage;
use crate::context::RenderDocumentElement;
use crate::context::RenderRealFootnoteDefinition;
use crate::error::CustomError;
use super::BlogPost;
use super::BlogPostPage;
pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
_post: &BlogPost,
page: &BlogPostPage,
) -> Result<RenderBlogPostPage, CustomError> {
let output_directory = output_directory.as_ref();
let output_file = output_file.as_ref();
let css_files = vec![
// get_web_path(
// config,
// output_directory,
// output_file,
// "stylesheet/reset.css",
// )?,
get_web_path(config, output_directory, output_file, "stylesheet/main.css")?,
];
let js_files = vec![get_web_path(
config,
output_directory,
output_file,
"blog_post.js",
)?];
let global_settings = GlobalSettings::new(page.title.clone(), css_files, js_files);
let page_header = PageHeader::new(
config.get_site_title().map(str::to_string),
Some(get_web_path(config, output_directory, output_file, "")?),
);
let link_to_blog_post = get_web_path(
config,
output_directory,
output_file,
output_file.strip_prefix(output_directory)?,
)?;
let children = {
let mut children = Vec::new();
for child in page.children.iter() {
children.push(RenderDocumentElement::new(
config,
output_directory,
output_file,
child,
)?);
}
children
};
let footnotes = {
let mut ret = Vec::new();
for footnote in page.footnotes.iter() {
ret.push(RenderRealFootnoteDefinition::new(
config,
output_directory,
output_file,
footnote,
)?);
}
ret
};
let ret = RenderBlogPostPage::new(
global_settings,
Some(page_header),
page.title.clone(),
Some(link_to_blog_post),
children,
footnotes,
);
Ok(ret)
}
pub(crate) fn get_web_path<D: AsRef<Path>, F: AsRef<Path>, P: AsRef<Path>>(
config: &Config,
output_directory: D,

View File

@@ -76,7 +76,6 @@ pub(crate) use clock::IClock;
pub(crate) use code::ICode;
pub(crate) use comment::IComment;
pub(crate) use comment_block::ICommentBlock;
pub(crate) use convert::convert_blog_post_page_to_render_context;
pub(crate) use convert::get_web_path;
pub(crate) use diary_sexp::IDiarySexp;
pub(crate) use document_element::IDocumentElement;