summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 02aac1930d9cdd8dcef644509988a376e282ed42 (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
44
45
46
47
48
49
50
51
use anyhow::{Context, Result};
use maud::{html, Markup};
use serde::Deserialize;

use self::page::Page;

mod page;

#[derive(Deserialize)]
struct Data {
    stories: Vec<Story>,
}

impl page::Page for Vec<Story> {
    fn page_title() -> String {
        String::from("Storys")
    }

    fn render_content(self) -> Markup {
        html!(
            @for story in self {
                (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 = data.stories.render_page();
    std::fs::write("dist/stories.html", stories_html.into_string())
        .with_context(|| "Failed to write dist/stories.html")?;
    Ok(())
}