use std::io::Result;
use std::path::PathBuf;
use crate::post::Post;
+use crate::template::TemplateContext;
pub fn generate(static_directory: &PathBuf, template_directory: &PathBuf, output_directory: &PathBuf, posts: &Vec<Post>) -> Result<()> {
let generators = available_generators();
+ let context = Post::to_template_context(&posts);
for generator in generators {
- generator(static_directory, template_directory, output_directory, posts)?;
+ generator(static_directory, template_directory, output_directory, &context)?;
}
Ok(())
}
-fn available_generators() -> Vec<fn(&PathBuf, &PathBuf, &PathBuf, &Vec<Post>) -> Result<()>> {
+fn available_generators() -> Vec<fn(&PathBuf, &PathBuf, &PathBuf, &TemplateContext) -> Result<()>> {
vec![
static_files::generate,
+ // These three are actually the same. Can generalize, don't know how in rust yet.
html::generate,
rss::generate,
txt::generate