summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 7f658ef4039799e85981a32c45277cd47d413162 (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
use tera::{Context, Tera};

use crate::works::Works;

mod works;

fn main() {
    let tera = match Tera::new("templates/**/*.html") {
        Ok(t) => t,
        Err(e) => {
            println!("Parsing error(s): {}", e);
            ::std::process::exit(1);
        }
    };

    let context = Context::new();

    let output = tera
        .render("index.html", &context)
        .expect("Failed to render index.html");

    std::fs::write("docs/index.html", output)
        .expect("Failed to write rendered output to index.html");

    let file = match std::fs::File::open(std::path::PathBuf::from("stories.json")) {
        Ok(file) => file,
        Err(err) => panic!("Trying to open stories.json in readmode - {:?}", err),
    };

    let stories = works::stories::Stories::new_from_file(file);
    println!("Stories: {:?}\n", stories);

    let context = stories.create_tera_context();
    println!("Context: {:?}\n", context);

    let stories_html_output = tera
        .render("stories.html", &context)
        .expect("Failed to render stories.html");

    std::fs::write("docs/stories.html", stories_html_output)
        .expect("Failed to write rendered output to stories.html");
}