]>
Commit | Line | Data |
---|---|---|
1 | use crate::template::{find, parse, Context}; | |
2 | use std::fs::write; | |
3 | use std::io::{Error, ErrorKind::Other, Result}; | |
4 | use std::path::Path; | |
5 | ||
6 | const FILENAME: &str = "feed.xml"; | |
7 | ||
8 | pub fn generate( | |
9 | _: &Path, | |
10 | template_directory: &Path, | |
11 | target: &Path, | |
12 | context: &Context, | |
13 | ) -> Result<()> { | |
14 | if let Some(template) = find(template_directory, FILENAME) { | |
15 | let parsed_template = | |
16 | parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse RSS template"))?; | |
17 | let rendered_template = parsed_template.render(context)?; | |
18 | let location = target.join(FILENAME); | |
19 | write(location, rendered_template)?; | |
20 | } | |
21 | Ok(()) | |
22 | } |