X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/2998247083406f914b3647cedd19abf5507bf2c6..5080a41dec9423dceb43a5c7ded8b9e1ddc0817e:/src/generator/rss.rs diff --git a/src/generator/rss.rs b/src/generator/rss.rs index dab7e50..6a13bb8 100644 --- a/src/generator/rss.rs +++ b/src/generator/rss.rs @@ -1,7 +1,20 @@ -use std::io::Result; +use std::fs::write; +use std::io::{Error, ErrorKind::Other, Result}; use std::path::PathBuf; -use crate::post::Post; +use crate::template::{find, parse, TemplateContext}; -pub fn generate(_: &PathBuf, _: &PathBuf, _: &PathBuf, _: &Vec) -> Result<()> { +const FILENAME: &str = "feed.xml"; + +pub fn generate(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> { + match find(template_directory, FILENAME) { + Some(template) => { + 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)?; + }, + None => {} + } Ok(()) }