blog-rs 0.2.0

Bare-bones static site generator for blogs
Documentation
use std::env;
use std::fs;
use std::io::Write;
use std::path::Path;

fn main() -> std::io::Result<()> {
    let out_dir = env::var("OUT_DIR").unwrap();
    let svg_out_path = Path::new(&out_dir).join("svgs.rs");
    let mut f = fs::File::create(&svg_out_path)?;

    let current_dir = env::current_dir()?;
    let svg_dir = current_dir.join("src/css/svg");

    for entry in fs::read_dir(&svg_dir)? {
        let entry = entry?;
        let path = entry.path();
        if path.is_file() && path.extension().and_then(|s| s.to_str()) == Some("svg") {
            let key = path.file_stem().unwrap().to_str().unwrap();
            let value = path.to_str().unwrap().replace("\\", "/");
            writeln!(
                f,
                "pub const SVG_{}: &str = include_str!(r#\"{}\"#);",
                key.to_uppercase(),
                value
            )?;
        }
    }

    let html_out_path = Path::new(&out_dir).join("htmls.rs");
    let mut f = fs::File::create(&html_out_path)?;
    let html_dir = current_dir.join("src/css/html");

    for entry in fs::read_dir(&html_dir)? {
        let entry = entry?;
        let path = entry.path();
        if path.is_file() && path.extension().and_then(|s| s.to_str()) == Some("html") {
            let key = path.file_stem().unwrap().to_str().unwrap();
            let value = path.to_str().unwrap().replace("\\", "/");
            writeln!(
                f,
                "pub const HTML_{}: &str = include_str!(r#\"{}\"#);",
                key.to_uppercase(),
                value
            )?;
        }
    }

    Ok(())
}