blob: e1460f27ebb8bdc8d475c485c36860e95c6e05c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
use anyhow::{Context, Result};
use maud::{html, Markup};
use serde::Deserialize;
#[derive(Deserialize)]
struct Data {
stories: Vec<Story>,
}
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(())
}
|