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