Create a Static Site Generation platform; Deduplicate hot reloading code (#2226)
* create static site generation helpers in the router crate * work on integrating static site generation into fullstack * move ssg into a separate crate * integrate ssg with the launch builder * simplify ssg example * fix static_routes for child routes * move CLI hot reloading websocket code into dioxus-hot-reload * fix some unused imports * use the same hot reloading websocket code for fullstack * fix fullstack hot reloading * move cli hot reloading logic into the hot reload crate * ssg example working with dx serve * add more examples * fix clippy * fix formatting * fix hot reload doctest imports * fix axum imports * don't run server doc tests * Fix hot reload websocket doc examples
This commit is contained in:
1 parent
460b70e0f0
commit
245003a5d4
59 files changed
+1507
-791
No files matched your search
@@ -3,12 +3,8 @@ use core::pin::Pin;
|
||||
use std::future::Future;
|
||||
use std::str::FromStr;
|
||||
|
||||
use dioxus_lib::prelude::*;
|
||||
use dioxus_ssr::incremental::{
|
||||
IncrementalRenderer, IncrementalRendererError, RenderFreshness, WrapBody,
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
use dioxus_lib::prelude::*;
|
||||
|
||||
/// Pre-cache all static routes.
|
||||
pub async fn pre_cache_static_routes<Rt, R: WrapBody + Send + Sync>(
|
||||
@@ -19,51 +15,20 @@ where
|
||||
Rt: Routable,
|
||||
<Rt as FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
for route in Rt::SITE_MAP
|
||||
.iter()
|
||||
.flat_map(|seg| seg.flatten().into_iter())
|
||||
{
|
||||
// check if this is a static segment
|
||||
let mut is_static = true;
|
||||
let mut full_path = String::new();
|
||||
for segment in &route {
|
||||
match segment {
|
||||
SegmentType::Child => {}
|
||||
SegmentType::Static(s) => {
|
||||
full_path += "/";
|
||||
full_path += s;
|
||||
}
|
||||
_ => {
|
||||
// skip routes with any dynamic segments
|
||||
is_static = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if is_static {
|
||||
match Rt::from_str(&full_path) {
|
||||
Ok(route) => {
|
||||
render_route(
|
||||
renderer,
|
||||
route,
|
||||
&mut tokio::io::sink(),
|
||||
|vdom| {
|
||||
Box::pin(async move {
|
||||
vdom.rebuild_in_place();
|
||||
vdom.wait_for_suspense().await;
|
||||
})
|
||||
},
|
||||
wrapper,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::info!("@ route: {}", full_path);
|
||||
tracing::error!("Error pre-caching static route: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for route in Rt::static_routes() {
|
||||
render_route(
|
||||
renderer,
|
||||
route,
|
||||
&mut tokio::io::sink(),
|
||||
|vdom| {
|
||||
Box::pin(async move {
|
||||
vdom.rebuild_in_place();
|
||||
vdom.wait_for_suspense().await;
|
||||
})
|
||||
},
|
||||
wrapper,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user