1
Fork 0
bauke-xyz/source/templates/mod.rs

34 lines
700 B
Rust

//! The main [`askama`] templates.
use std::{
fs::{create_dir_all, write},
path::Path,
};
use askama::Template;
use color_eyre::Result;
/// The template for the home page.
#[derive(Debug, Template)]
#[template(path = "index.html")]
pub struct Index {
/// The text for the `<title>` element.
pub page_title: String,
}
impl Index {
/// Build, minify and write the template.
pub fn write(public_dir: &Path) -> Result<()> {
let destination = public_dir.join("index.html");
create_dir_all(destination.parent().unwrap())?;
let template = Self {
page_title: "Bauke".to_string(),
};
write(destination, crate::minify::html(template.render()?)?)?;
Ok(())
}
}