+use std::fs::write;
use std::io::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<Post>) -> 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 rendered_template = parsed_template.render(context);
+ let location = target.join(FILENAME);
+ write(location, rendered_template)?;
},
None => {}
}