Skip to content

Commit

Permalink
Update static build html structures (#20)
Browse files Browse the repository at this point in the history
* fix: improve static build output structure

* feat: update version to v0.8.3
  • Loading branch information
Valerioageno authored Jul 27, 2024
1 parent 3fd5f16 commit 170c5ea
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/tuono/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuono"
version = "0.8.2"
version = "0.8.3"
edition = "2021"
authors = ["V. Ageno <[email protected]>"]
description = "The react/rust fullstack framework"
Expand Down
1 change: 1 addition & 0 deletions crates/tuono/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
6 changes: 3 additions & 3 deletions crates/tuono/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
25 changes: 24 additions & 1 deletion crates/tuono/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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))
}
}
}
4 changes: 2 additions & 2 deletions crates/tuono_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuono_lib"
version = "0.8.2"
version = "0.8.3"
edition = "2021"
authors = ["V. Ageno <[email protected]>"]
description = "The react/rust fullstack framework"
Expand Down Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/tuono_lib_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion packages/fs-router-vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/lazy-fn-vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/tuono/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 170c5ea

Please sign in to comment.