]> git.r.bdr.sh - rbdr/blog/blob - src/archiver/gemini.rs
3b04bcf4ad92d98ea4d3f90511c9ee09c7ea60e2
[rbdr/blog] / src / archiver / gemini.rs
1 use std::fs::write;
2 use std::io::{Error, ErrorKind::Other, Result};
3 use std::path::PathBuf;
4 use crate::template::{find, parse, TemplateContext};
5
6 const FILENAME: &str = "index.gmi";
7
8 pub fn archive(_: &PathBuf, template_directory: &PathBuf, target: &PathBuf, context: &TemplateContext) -> Result<()> {
9 match find(template_directory, FILENAME) {
10 Some(template) => {
11 let parsed_template = parse(&template)
12 .ok_or_else(|| Error::new(Other, "Unable to parse Gemini Archive template"))?;
13 let rendered_template = parsed_template.render(context)?;
14 let location = target.join(FILENAME);
15 write(location, rendered_template)?;
16 },
17 None => {}
18 }
19 Ok(())
20 }