X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/2998247083406f914b3647cedd19abf5507bf2c6..c4b892b16fb92c7d89eaee0b1588c52c8836216b:/src/generator/html.rs?ds=sidebyside diff --git a/src/generator/html.rs b/src/generator/html.rs index 0b258bf..ab47b7a 100644 --- a/src/generator/html.rs +++ b/src/generator/html.rs @@ -1,16 +1,18 @@ -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}; +use crate::template::{find, parse, TemplateContext}; -pub fn generate(_: &PathBuf, template_directory: &PathBuf, _: &PathBuf, _: &Vec) -> Result<()> { - println!("READING TEMP"); - match find(template_directory, "index.html") { +const FILENAME: &str = "index.html"; + +pub fn generate(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> { + match find(template_directory, FILENAME) { Some(template) => { - let parsed_template = parse(&template); - for token in parsed_template.tokens { - println!("TOKEN {}", token); - } + let parsed_template = parse(&template) + .ok_or_else(|| Error::new(Other, "Unable to parse HTML template"))?; + let rendered_template = parsed_template.render(context)?; + let location = target.join(FILENAME); + write(location, rendered_template)?; }, None => {} }