diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2026-03-21 12:47:54 +0100 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2026-03-21 12:47:54 +0100 |
| commit | 7fd554c42a0f46e4dd8dec6cdfc3a18c274527cf (patch) | |
| tree | e28b306957904391c38f67c3a6b1011c58e18a3d /src | |
| parent | f491ed95a3bc82c31c70b0f38ed841408576ec0c (diff) | |
Add prototype for TOML-based website data source
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 43 |
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(()) +} |
