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

58 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-13 23:50:38 +00:00
use std::{
fs::{create_dir_all, write},
path::Path,
};
2021-11-26 13:08:13 +00:00
use askama::Template;
2021-12-13 23:50:38 +00:00
use color_eyre::Result;
2021-11-26 13:08:13 +00:00
#[derive(Debug, Template)]
#[template(path = "index.html")]
pub struct Index {
pub page_title: String,
}
2021-12-13 23:50:38 +00:00
impl Index {
pub fn write(public_dir: &Path) -> Result<()> {
let destination = public_dir.join("index.html");
create_dir_all(destination.parent().unwrap())?;
let template = Self {
2022-03-28 12:59:01 +00:00
page_title: "Bauke".to_string(),
2021-12-13 23:50:38 +00:00
};
write(destination, template.render()?)?;
Ok(())
}
}
2021-11-26 13:08:13 +00:00
#[derive(Debug, Template)]
#[template(path = "userstyles.html")]
pub struct Userstyles {
pub page_title: String,
pub styles: Vec<userstyles::Userstyle>,
}
2021-12-13 23:50:38 +00:00
impl Userstyles {
pub fn write(public_dir: &Path) -> Result<()> {
let destination = public_dir.join("userstyles/index.html");
create_dir_all(destination.parent().unwrap())?;
let styles = userstyles::ALL_USERSTYLES
.iter()
.map(|target| userstyles::Userstyle::load(target))
.flatten()
.collect();
let template = Self {
2022-03-28 12:07:15 +00:00
page_title: "Bauke".to_string(),
2021-12-13 23:50:38 +00:00
styles,
};
write(destination, template.render()?)?;
Ok(())
}
}