aboutsummaryrefslogtreecommitdiff
path: root/src/generator/mod.rs
blob: 293ad7df59d16af38a5d1c4dbe547471a86f3bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mod html;
mod rss;
mod static_files;
mod txt;

use crate::post::Post;
use crate::template::TemplateContext;
use std::io::Result;
use std::path::PathBuf;

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,
            &context,
        )?;
    }
    Ok(())
}

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,
    ]
}