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
@@ -233,23 +233,6 @@ type SiteMapFlattened<'a> = FlatMap<
|
||||
fn(&SiteMapSegment) -> Vec<Vec<SegmentType>>,
|
||||
>;
|
||||
|
||||
fn seg_strs_to_route<T>(segs_maybe: &Option<Vec<&str>>) -> Option<T>
|
||||
where
|
||||
T: Routable,
|
||||
{
|
||||
if let Some(str) = seg_strs_to_str(segs_maybe) {
|
||||
T::from_str(&str).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn seg_strs_to_str(segs_maybe: &Option<Vec<&str>>) -> Option<String> {
|
||||
segs_maybe
|
||||
.as_ref()
|
||||
.map(|segs| String::from('/') + &segs.join("/"))
|
||||
}
|
||||
|
||||
/// Something that can be:
|
||||
/// 1. Converted from a route.
|
||||
/// 2. Converted to a route.
|
||||
@@ -354,16 +337,20 @@ pub trait Routable: FromStr + Display + Clone + 'static {
|
||||
/// Example static route: `#[route("/static/route")]`
|
||||
fn static_routes() -> Vec<Self> {
|
||||
Self::flatten_site_map()
|
||||
.filter_map(|route| {
|
||||
let route_if_static = &route
|
||||
.iter()
|
||||
.map(|segment| match segment {
|
||||
SegmentType::Static(s) => Some(*s),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Option<Vec<_>>>();
|
||||
.filter_map(|segments| {
|
||||
let mut route = String::new();
|
||||
for segment in segments.iter() {
|
||||
match segment {
|
||||
SegmentType::Static(s) => {
|
||||
route.push('/');
|
||||
route.push_str(s)
|
||||
}
|
||||
SegmentType::Child => {}
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
|
||||
seg_strs_to_route(route_if_static)
|
||||
route.parse().ok()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -413,6 +400,40 @@ pub enum SegmentType {
|
||||
Child,
|
||||
}
|
||||
|
||||
impl SegmentType {
|
||||
/// Try to convert this segment into a static segment.
|
||||
pub fn to_static(&self) -> Option<&'static str> {
|
||||
match self {
|
||||
SegmentType::Static(s) => Some(*s),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to convert this segment into a dynamic segment.
|
||||
pub fn to_dynamic(&self) -> Option<&'static str> {
|
||||
match self {
|
||||
SegmentType::Dynamic(s) => Some(*s),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to convert this segment into a catch all segment.
|
||||
pub fn to_catch_all(&self) -> Option<&'static str> {
|
||||
match self {
|
||||
SegmentType::CatchAll(s) => Some(*s),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to convert this segment into a child segment.
|
||||
pub fn to_child(&self) -> Option<()> {
|
||||
match self {
|
||||
SegmentType::Child => Some(()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SegmentType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match &self {
|
||||
|
||||
Reference in new issue
Block a user