]> git.r.bdr.sh - rbdr/blog/blob - src/generator/mod.rs
f0fef7585fd9e7162d6b5f6650d4bbcb577277b8
[rbdr/blog] / src / generator / mod.rs
1 mod static_files;
2 mod html;
3 mod rss;
4 mod txt;
5
6 use std::io::Result;
7 use std::path::PathBuf;
8 use crate::post::Post;
9 use crate::template::TemplateContext;
10
11 pub fn generate(static_directory: &PathBuf, template_directory: &PathBuf, output_directory: &PathBuf, posts: &Vec<Post>) -> Result<()> {
12 let generators = available_generators();
13 let context = Post::to_template_context(&posts);
14 for generator in generators {
15 generator(static_directory, template_directory, output_directory, &context)?;
16 }
17 Ok(())
18 }
19
20
21 fn available_generators() -> Vec<fn(&PathBuf, &PathBuf, &PathBuf, &TemplateContext) -> Result<()>> {
22 vec![
23 static_files::generate,
24 html::generate,
25 rss::generate,
26 txt::generate
27 ]
28 }