aboutsummaryrefslogtreecommitdiff
path: root/src/generator/rss.rs
blob: e79694e96c15de7cd48c95f84324c074e7e6f46b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::template::{find, parse, Context};
use std::fs::write;
use std::io::{Error, ErrorKind::Other, Result};
use std::path::Path;

const FILENAME: &str = "feed.xml";

pub fn generate(
    _: &Path,
    template_directory: &Path,
    target: &Path,
    context: &Context,
) -> Result<()> {
    if let Some(template) = find(template_directory, FILENAME) {
        let parsed_template =
            parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse RSS template"))?;
        let rendered_template = parsed_template.render(context)?;
        let location = target.join(FILENAME);
        write(location, rendered_template)?;
    }
    Ok(())
}