use regex::Regex; use std::{collections::HashSet, env, error::Error, fs, path::Path, process::Command}; fn escape_template(v: &str) -> Result { let cant_escape = "\\{"; if v.contains(cant_escape) { return Err(format!("can't escape {cant_escape}")); } Ok(v.replace("{", "\\{")) } fn main() -> Result<(), Box> { println!("cargo:rerun-if-changed=migrations"); println!("cargo:rerun-if-changed=website"); let out_dir = env::var_os("OUT_DIR").unwrap(); let website_dir = Path::new(&out_dir).join("website"); let templates_dir = Path::new(&out_dir).join("templates"); fs::create_dir_all(&templates_dir)?; let status = Command::new("mdbook") .arg("build") .arg("--dest-dir") .arg(&website_dir) .current_dir("website") .status() .map_err(|e| format!("Can't run mdbook: {e}"))?; if !status.success() { return Err(format!("mdbook exited with an error: {status:?}").into()); } let sub_template_path = website_dir.join("subscription/index.html"); let sub_template = fs::read_to_string(&sub_template_path) .map_err(|e| format!("Error reading {}: {e}", sub_template_path.display()))?; let regex = Regex::new(r#"(?s)