From 21c8b35bbacaf10de11aa7a979f27cae484eb9b0 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 11 Apr 2024 01:49:26 -0700 Subject: [PATCH] use templates generated from website.git --- .gitmodules | 3 ++ Cargo.lock | 3 +- Cargo.toml | 7 +++-- build.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/app.rs | 35 ++++++++++------------- website | 1 + 6 files changed, 104 insertions(+), 25 deletions(-) create mode 100644 .gitmodules create mode 160000 website diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..819396e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "website"] + path = website + url = https://git.libre-chip.org/libre-chip/website.git diff --git a/Cargo.lock b/Cargo.lock index a841d33..f9b6cc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2507,7 +2507,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "subscribe-list" -version = "0.1.0" +version = "0.1.1" dependencies = [ "actix-session", "actix-web", @@ -2525,6 +2525,7 @@ dependencies = [ "listenfd", "log", "openidconnect", + "regex", "reqwest", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index e1990f3..5f88576 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "subscribe-list" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Jacob Lifshay "] description = "web server for managing subscriptions" @@ -33,6 +33,9 @@ tinytemplate = "1.2.1" tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } toml = { version = "0.8.12", features = ["preserve_order"] } +[build-dependencies] +regex = "1.10.4" + [package.metadata.deb] depends = ["$auto", "adduser (>= 3.11)"] assets = [ @@ -44,4 +47,4 @@ maintainer-scripts = "debian" [package.metadata.deb.systemd-units] unit-name = "subscribe-list" unit-scripts = "." -enable = false \ No newline at end of file +enable = false diff --git a/build.rs b/build.rs index 3a8149e..47838f7 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,79 @@ -fn main() { - println!("cargo:rerun-if-changed=migrations"); +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)