use anyhow::{Context, Result}; use maud::{html, Markup}; use serde::Deserialize; #[derive(Deserialize)] struct Data { stories: Vec, } impl Data { fn render_stories(self) -> Markup { html!( @for story in self.stories { (story.render_as_card()) } ) } } #[derive(Deserialize)] struct Story { name: String, description: String, } impl Story { fn render_as_card(self) -> Markup { html!(card { span { (self.name) } span { (self.description) } }) } } fn main() -> Result<()> { let data_file_content = std::fs::read_to_string("data.toml").with_context(|| "Failed to read data.toml")?; let data: Data = toml::from_str(&data_file_content)?; let stories_html = html!((data.render_stories())); std::fs::write("dist/stories.html", stories_html.into_string()) .with_context(|| "Failed to write dist/stories.html")?; Ok(()) }