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

use crate::works::Works;

mod works;

fn main() -> Result<()> {
    // new tera instance
    let tera = Tera::new("templates/**/*.html").context("Failed to create new Tera instance")?;

    // render index.html file
    let context = tera::Context::new();
    let output = tera
        .render("index.html", &context)
        .context("Failed to render index.html")?;
    std::fs::write("docs/index.html", output).context("Failed to write index.html")?;

    // render stories.html file
    let stories = std::rc::Rc::new(works::stories::Stories::new_from_file(
        &std::fs::File::open(std::path::PathBuf::from("stories.json"))
            .context("Failed to open stories.json")?,
    )?);
    std::rc::Rc::clone(&stories)
        .render_overview_page(&tera, "stories")
        .context("Failed to render overview page for stories")?;
    std::rc::Rc::clone(&stories)
        .render_single_pages(&tera, "story")
        .context("Failed to render single pages for stories")?;
    Ok(())
}