use std::{borrow::Cow, path::Path};

use databake::Bake;
use jotdown::Event;

fn main() {
    let out = std::env::var("OUT_DIR").unwrap();

    let jots = glob::glob("src/*.jot").unwrap();

    for path in jots.map(|p| p.unwrap()) {
        let file = std::fs::read_to_string(&path).unwrap();
        let name = path.file_name().unwrap();

        let jot: Cow<'_, [Event<'_>]> = Cow::Owned(jotdown::Parser::new(&file).collect::<Vec<_>>());

        std::fs::write(
            Path::new(&out).join(name),
            jot.bake(&Default::default()).to_string(),
        )
        .unwrap();
    }
}
