From 170c5ea098565f5e238513477bd3e103488467b4 Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:42:28 +0200 Subject: [PATCH] Update static build html structures (#20) * fix: improve static build output structure * feat: update version to v0.8.3 --- crates/tuono/Cargo.toml | 2 +- crates/tuono/src/app.rs | 1 + crates/tuono/src/cli.rs | 6 ++--- crates/tuono/src/route.rs | 25 ++++++++++++++++++++- crates/tuono_lib/Cargo.toml | 4 ++-- crates/tuono_lib_macros/Cargo.toml | 2 +- packages/fs-router-vite-plugin/package.json | 2 +- packages/lazy-fn-vite-plugin/package.json | 2 +- packages/tuono/package.json | 2 +- 9 files changed, 35 insertions(+), 11 deletions(-) diff --git a/crates/tuono/Cargo.toml b/crates/tuono/Cargo.toml index 6f665617..6e3334fa 100644 --- a/crates/tuono/Cargo.toml +++ b/crates/tuono/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono" -version = "0.8.2" +version = "0.8.3" edition = "2021" authors = ["V. Ageno "] description = "The react/rust fullstack framework" diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index d9f64e8a..4fe6c764 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -63,6 +63,7 @@ impl App { .unwrap() .replace(&format!("{base_path_str}/src/routes"), "") .replace(".rs", "") + .replace(".mdx", "") .replace(".tsx", ""); if entry.extension().unwrap() == "rs" { diff --git a/crates/tuono/src/cli.rs b/crates/tuono/src/cli.rs index 22a0e807..54d6351a 100644 --- a/crates/tuono/src/cli.rs +++ b/crates/tuono/src/cli.rs @@ -104,9 +104,9 @@ pub fn app() -> std::io::Result<()> { sleep(Duration::from_secs(1)) } - app.route_map - .iter() - .for_each(|(_, route)| route.save_ssg_html(&reqwest)); + for (_, route) in app.route_map { + route.save_ssg_html(&reqwest) + } // Close server let _ = rust_server.kill(); diff --git a/crates/tuono/src/route.rs b/crates/tuono/src/route.rs index 2c748517..2abaf76c 100644 --- a/crates/tuono/src/route.rs +++ b/crates/tuono/src/route.rs @@ -81,7 +81,7 @@ impl Route { .send() .unwrap(); - let file_path = PathBuf::from(format!("out/static{}.html", &self.path)); + let file_path = self.html_file_path(); let parent_dir = file_path.parent().unwrap(); @@ -123,6 +123,11 @@ impl Route { io::copy(&mut response, &mut data_file).expect("Failed to write the JSON on the file"); } } + + fn html_file_path(&self) -> PathBuf { + let cleaned_path = self.path.replace("index", ""); + PathBuf::from(format!("out/static{}/index.html", cleaned_path)) + } } #[cfg(test)] @@ -162,4 +167,22 @@ mod tests { assert_eq!(dyn_info.axum_route, "/:posts"); assert_eq!(dyn_info.module_import, "dyn_posts"); } + + #[test] + fn should_define_the_correct_html_build_path() { + let routes = [ + ("/index", "out/static/index.html"), + ("/documentation", "out/static/documentation/index.html"), + ( + "/documentation/routing", + "out/static/documentation/routing/index.html", + ), + ]; + + for (path, html) in routes { + let route = Route::new(path.to_string()); + + assert_eq!(route.html_file_path(), PathBuf::from(html)) + } + } } diff --git a/crates/tuono_lib/Cargo.toml b/crates/tuono_lib/Cargo.toml index b29959c0..146b2e5a 100644 --- a/crates/tuono_lib/Cargo.toml +++ b/crates/tuono_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib" -version = "0.8.2" +version = "0.8.3" edition = "2021" authors = ["V. Ageno "] description = "The react/rust fullstack framework" @@ -32,7 +32,7 @@ regex = "1.10.5" either = "1.13.0" tower-http = {version = "0.5.2", features = ["fs"]} -tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.8.2"} +tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.8.3"} # Match the same version used by axum tokio-tungstenite = "0.21.0" futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } diff --git a/crates/tuono_lib_macros/Cargo.toml b/crates/tuono_lib_macros/Cargo.toml index 10d9d4f2..a50a4bab 100644 --- a/crates/tuono_lib_macros/Cargo.toml +++ b/crates/tuono_lib_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tuono_lib_macros" -version = "0.8.2" +version = "0.8.3" edition = "2021" description = "The react/rust fullstack framework" keywords = [ "react", "typescript", "fullstack", "web", "ssr"] diff --git a/packages/fs-router-vite-plugin/package.json b/packages/fs-router-vite-plugin/package.json index 7dcead60..84fd02cd 100644 --- a/packages/fs-router-vite-plugin/package.json +++ b/packages/fs-router-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-fs-router-vite-plugin", - "version": "0.8.2", + "version": "0.8.3", "description": "Plugin for the tuono's file system router. Tuono is the react/rust fullstack framework", "scripts": { "dev": "vite build --watch", diff --git a/packages/lazy-fn-vite-plugin/package.json b/packages/lazy-fn-vite-plugin/package.json index 934295f9..ff700374 100644 --- a/packages/lazy-fn-vite-plugin/package.json +++ b/packages/lazy-fn-vite-plugin/package.json @@ -1,6 +1,6 @@ { "name": "tuono-lazy-fn-vite-plugin", - "version": "0.8.2", + "version": "0.8.3", "description": "Plugin for the tuono's lazy fn. Tuono is the react/rust fullstack framework", "scripts": { "dev": "vite build --watch", diff --git a/packages/tuono/package.json b/packages/tuono/package.json index 0401d5d3..f977ed2a 100644 --- a/packages/tuono/package.json +++ b/packages/tuono/package.json @@ -1,6 +1,6 @@ { "name": "tuono", - "version": "0.8.2", + "version": "0.8.3", "description": "The react/rust fullstack framework", "scripts": { "dev": "vite build --watch",