aboutsummaryrefslogtreecommitdiff
path: root/src/archiver/gopher.rs
blob: fc0c04f221a6516a58397ee652de76e5a252a368 (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, TemplateContext};
use std::fs::write;
use std::io::{Error, ErrorKind::Other, Result};
use std::path::Path;

const FILENAME: &str = "index.gph";

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