summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..e1460f2
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,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(())
+}