]>
Commit | Line | Data |
---|---|---|
1 | mod html; | |
2 | mod rss; | |
3 | mod static_files; | |
4 | mod txt; | |
5 | ||
6 | use crate::post::Post; | |
7 | use crate::template::Context; | |
8 | use std::io::Result; | |
9 | use std::path::Path; | |
10 | ||
11 | type Generator = fn(&Path, &Path, &Path, &Context) -> Result<()>; | |
12 | ||
13 | pub fn generate( | |
14 | static_directory: &Path, | |
15 | template_directory: &Path, | |
16 | output_directory: &Path, | |
17 | posts: &[Post], | |
18 | ) -> Result<()> { | |
19 | let generators = available_generators(); | |
20 | let context = Post::to_template_context(posts); | |
21 | for generator in generators { | |
22 | generator( | |
23 | static_directory, | |
24 | template_directory, | |
25 | output_directory, | |
26 | &context, | |
27 | )?; | |
28 | } | |
29 | Ok(()) | |
30 | } | |
31 | ||
32 | fn available_generators() -> Vec<Generator> { | |
33 | vec![ | |
34 | static_files::generate, | |
35 | // These three are actually the same. Can generalize, don't know how in rust yet. | |
36 | html::generate, | |
37 | rss::generate, | |
38 | txt::generate, | |
39 | ] | |
40 | } |