From 3025f327c2123b6fd64978ebe1b657dfb785be3c Mon Sep 17 00:00:00 2001 From: Phosphorus-M Date: Wed, 1 Jan 2025 15:07:28 -0300 Subject: [PATCH] feat: update site root to 'dist', enhance VSCode settings, and improve routing for SSR --- .github/workflows/deploy.yml | 0 .gitignore | 2 ++ .vscode/settings.json | 1 + Cargo.toml | 2 +- src/app.rs | 7 +++---- src/main.rs | 9 +++++++-- 6 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index ac5c7c5..c666825 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ Cargo.lock node_modules +dist + diff --git a/.vscode/settings.json b/.vscode/settings.json index 25139a6..5549e0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,4 +16,5 @@ "strings": true }, "css.validate": false, + "rust-analyzer.cargo.features": ["ssr"] } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 155e124..5239f49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ tailwind-input-file = "style/input.css" tailwind-config-file = "tailwind.config.js" # The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup. -site-root = "target/site" +site-root = "dist" # The site-root relative folder where all compiled output (JS, WASM and CSS) is written # Defaults to pkg diff --git a/src/app.rs b/src/app.rs index 3675691..cacbeef 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,8 +1,7 @@ use leptos::prelude::*; use leptos_meta::{provide_meta_context, MetaTags, Stylesheet, Title}; use leptos_router::{ - components::{Route, Router, Routes}, - StaticSegment, + components::{Route, Router, Routes}, static_routes::StaticRoute, SsrMode, StaticSegment }; use reactive_stores::Store; @@ -39,13 +38,13 @@ pub fn App() -> impl IntoView { // sets the document title - + <Title text="Rust PerĂº"/> // content for this welcome page <Router> <main> <Routes fallback=|| "Page not found.".into_view()> - <Route path=StaticSegment("") view=HomePage/> + <Route path=StaticSegment("") view=HomePage ssr=SsrMode::Static(StaticRoute::new())/> </Routes> </main> </Router> diff --git a/src/main.rs b/src/main.rs index ead9e60..d03e3eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,14 +5,19 @@ async fn main() { use axum::Router; use leptos::logging::log; use leptos::prelude::*; - use leptos_axum::{generate_route_list, LeptosRoutes}; + use leptos_axum::{generate_route_list_with_ssg, LeptosRoutes}; use rust_peru::app::*; let conf = get_configuration(None).unwrap(); let addr = conf.leptos_options.site_addr; let leptos_options = conf.leptos_options; // Generate the list of routes in your Leptos App - let routes = generate_route_list(App); + let (routes, static_route_generator) = generate_route_list_with_ssg({ + let leptos_options = leptos_options.clone(); + move || shell(leptos_options.clone()) + }); + + static_route_generator.generate(&leptos_options).await; let app = Router::new() .leptos_routes(&leptos_options, routes, {