From 5ef37275ec504dc2e406d8feadca2e388e8d7fc9 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Tue, 21 Jan 2025 21:55:27 +0100 Subject: [PATCH] add flowbite --- .gitignore | 4 +++- build.rs | 26 ++++++++++++++++++++------ src/asset.rs | 24 +++++++++++++++++++++++- src/ui/components/shell.rs | 2 ++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 3077a23..c76a005 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target -src/htmx.min.js \ No newline at end of file +src/htmx.min.js +src/flowbite.min.css +src/flowbite.min.js \ No newline at end of file diff --git a/build.rs b/build.rs index 24382b4..1189a1c 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,9 @@ use std::fs; use std::path::Path; -fn main() { - let url = "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js"; - let dest_path = Path::new("src/htmx.min.js"); - - println!("Downloading htmx.min.js from {url}"); +pub fn download_file(url: &str, dest_path: &str) { + println!("Downloading {dest_path} from {url}"); + let dest_path = Path::new(dest_path); let response = reqwest::blocking::get(url) .expect("Failed to send HTTP request") .error_for_status() @@ -13,7 +11,23 @@ fn main() { let content = response.bytes().expect("Failed to read response body"); - fs::write(dest_path, &content).expect("Failed to write htmx.min.js to destination"); + fs::write(dest_path, &content).expect("Failed to write file to destination"); +} + +fn main() { + download_file( + "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js", + "src/htmx.min.js", + ); + + download_file( + "https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.min.css", + "src/flowbite.min.css", + ); + download_file( + "https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.min.js", + "src/flowbite.min.js", + ); println!("cargo:rerun-if-changed=build.rs"); } diff --git a/src/asset.rs b/src/asset.rs index 659380e..0c878d7 100644 --- a/src/asset.rs +++ b/src/asset.rs @@ -10,12 +10,34 @@ pub fn htmx_script_route() -> DataResponse { ) } +#[get("/assets/flowbite.min.css")] +pub fn flowbite_css() -> DataResponse { + DataResponse::new( + include_str!("flowbite.min.css").as_bytes().to_vec(), + "text/css".to_string(), + Some(60 * 60 * 24 * 3), + ) +} + +#[get("/assets/flowbite.min.s")] +pub fn flowbite_js() -> DataResponse { + DataResponse::new( + include_str!("flowbite.min.js").as_bytes().to_vec(), + "application/javascript".to_string(), + Some(60 * 60 * 24 * 3), + ) +} + pub trait AssetRoutes { fn mount_assets(self) -> Self; } impl AssetRoutes for rocket::Rocket { fn mount_assets(self) -> Self { - self.mount("/", routes![crate::asset::htmx_script_route]) + self.mount("/", routes![ + crate::asset::htmx_script_route, + crate::asset::flowbite_css, + crate::asset::flowbite_js + ]) } } diff --git a/src/ui/components/shell.rs b/src/ui/components/shell.rs index 8db6011..0e529be 100644 --- a/src/ui/components/shell.rs +++ b/src/ui/components/shell.rs @@ -64,6 +64,8 @@ impl Shell { @if self.ui { script src="https://cdn.tailwindcss.com" {}; script src="/assets/htmx.min.js" {}; + script src="/assets/flowbite.min.js" {}; + link href="/assets/flowbite.min.css" rel="stylesheet" {}; meta name="viewport" content="width=device-width, initial-scale=1.0"; }; (self.head)