mod.rs (777B)
1 use crate::{config::Config, error::{Error, Result}, post::Post}; 2 use super::Exporter; 3 4 mod render; 5 6 const TEMPLATE: &str = include_str!("template.html"); 7 8 #[derive(Clone)] 9 pub struct HtmlExporter; 10 11 impl Exporter for HtmlExporter { 12 fn export(&self, posts: &[Post], config: &Config) -> Result<()> { 13 if posts.is_empty() { 14 return Err(Error::NoPosts); 15 } 16 17 std::fs::create_dir_all(&config.dir)?; 18 let posts_html = posts 19 .iter() 20 .map(|p| render::render_post(p, config.files, config.thumb)) 21 .collect::<Vec<String>>() 22 .join("\n"); 23 let index_html = TEMPLATE.replace("{{posts}}", &posts_html); 24 std::fs::write(config.dir.join("index.html"), index_html)?; 25 26 Ok(()) 27 } 28 }