aboutsummaryrefslogtreecommitdiff
path: root/src/archiver/gopher.rs
blob: 454e8c4ba8b6feeda7ea9b831999a798400a7314 (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.gph";

pub fn archive(
    _: &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 Gopher Archive template"))?;
        let rendered_template = parsed_template.render(context)?;
        let location = target.join(FILENAME);
        write(location, rendered_template)?;
    }
    Ok(())
}