aboutsummaryrefslogtreecommitdiff
path: root/src/generator/html.rs
blob: 70cc3206c0fac5f3a4534ffe2f2023a2d2102a11 (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 = "index.html";

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 HTML template"))?;
        let rendered_template = parsed_template.render(context)?;
        let location = target.join(FILENAME);
        write(location, rendered_template)?;
    }
    Ok(())
}