From 06070a820f5a92c2671242b044cec5f6b3dacff5 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 1 Apr 2023 17:54:07 -0400 Subject: build javascript files with esbuild Signed-off-by: Xe Iaso --- lib/xesite_templates/Cargo.toml | 3 ++- lib/xesite_templates/src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/xesite_templates/Cargo.toml b/lib/xesite_templates/Cargo.toml index fc852b0..dbfa1d3 100644 --- a/lib/xesite_templates/Cargo.toml +++ b/lib/xesite_templates/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +serde_json = "1" uuid = { version = "1", features = [ "v4" ] } xesite_types = { path = "../xesite_types" } @@ -13,4 +14,4 @@ xesite_types = { path = "../xesite_types" } [dependencies.maud] git = "https://github.com/Xe/maud" rev = "a40596c42c7603cc4610bbeddea04c4bd8b312d9" -features = ["axum"] \ No newline at end of file +features = ["axum"] diff --git a/lib/xesite_templates/src/lib.rs b/lib/xesite_templates/src/lib.rs index 767ac45..b1945e9 100644 --- a/lib/xesite_templates/src/lib.rs +++ b/lib/xesite_templates/src/lib.rs @@ -228,3 +228,40 @@ pub fn toot_embed(u: User, t: Toot) -> Markup { } } } + +pub fn xeact_component(name: &str, data: serde_json::Value) -> Markup { + let uuid = uuid::Uuid::new_v4(); + let uuid = format!("{uuid}").replace("-", ""); + + let script = PreEscaped(format!( + r#" + +"#, + data=serde_json::to_string(&data).unwrap(), + )); + + html! { + div id=(uuid) { + noscript { + div.warning { + (conv("Aoi".into(), "coffee".into(), PreEscaped("This dynamic component requires JavaScript to function, sorry!".to_string()))) + } + } + } + (script) + } +} -- cgit v1.2.3