Rust library to generate static websites
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(build): Fixes build not working when a dynamic route didn't return any routes

+27 -28
+5 -4
crates/framework/src/lib.rs
··· 187 187 }; 188 188 189 189 for route in routes { 190 - let routes = route.routes(&dynamic_route_context); 191 - match routes.is_empty() { 192 - true => { 190 + match route.route_type() { 191 + page::RouteType::Static => { 193 192 let route_start = SystemTime::now(); 194 193 let mut page_assets = assets::PageAssets { 195 194 assets_dir: options.assets_dir.clone().into(), ··· 227 226 params: None, 228 227 }); 229 228 } 230 - false => { 229 + page::RouteType::Dynamic => { 230 + let routes = route.routes(&dynamic_route_context); 231 + 231 232 info!(target: "build", "{}", route.route_raw().to_string().bold()); 232 233 233 234 for params in routes {
+12 -4
crates/framework/src/page.rs
··· 64 64 } 65 65 } 66 66 67 - pub trait DynamicPage { 67 + pub trait DynamicRoute { 68 + // Intentionally does not have a default implementation even though it'd be useful in our macros in order to force 69 + // the user to implement it explicitly, even if it's just returning an empty Vec. 68 70 fn routes(&self, context: &DynamicRouteContext) -> Vec<RouteParams>; 69 71 } 70 72 73 + pub enum RouteType { 74 + Static, 75 + Dynamic, 76 + } 77 + 71 78 pub trait InternalPage { 79 + fn route_type(&self) -> RouteType; 72 80 fn route_raw(&self) -> String; 73 81 fn route(&self, params: &RouteParams) -> String; 74 82 fn file_path(&self, params: &RouteParams) -> PathBuf; ··· 84 92 Self: Sized; 85 93 } 86 94 87 - pub trait FullPage: Page + InternalPage + DynamicPage + Sync {} 95 + pub trait FullPage: Page + InternalPage + DynamicRoute + Sync {} 88 96 89 97 pub mod prelude { 90 98 pub use super::{ 91 - DynamicPage, DynamicRouteContext, FullPage, InternalPage, Page, RenderResult, RouteContext, 92 - RouteParams, 99 + DynamicRoute, DynamicRouteContext, FullPage, InternalPage, Page, RenderResult, 100 + RouteContext, RouteParams, 93 101 }; 94 102 pub use crate::assets::Asset; 95 103 pub use maudit_macros::{route, Params};
+10 -20
crates/macros/src/lib.rs
··· 39 39 let dynamic_page_impl = match params.is_empty() { 40 40 false => quote! {}, 41 41 true => quote! { 42 - impl maudit::page::DynamicPage for #struct_name { 42 + impl maudit::page::DynamicRoute for #struct_name { 43 43 fn routes(&self, _: &maudit::page::DynamicRouteContext) -> Vec<maudit::page::RouteParams> { 44 44 Vec::new() 45 45 } ··· 57 57 }) 58 58 .collect::<Vec<_>>(); 59 59 60 - let struct_def_params = params 61 - .iter() 62 - .map(|v| { 63 - let key = format_ident!("{}", v.key); 64 - quote! { #key: String } 65 - }) 66 - .collect::<Vec<_>>(); 67 - 68 60 let path_for_route = make_params_dynamic(&path, &params, 0); 69 61 let file_path_for_route = url_to_file_path(&path, attrs.is_endpoint_file, &params); 70 62 71 - let raw_params = format_ident!("RawParams_{}", struct_name); 63 + let route_type = if params.is_empty() { 64 + quote! { maudit::page::RouteType::Static } 65 + } else { 66 + quote! { maudit::page::RouteType::Dynamic } 67 + }; 72 68 73 69 let expanded = quote! { 74 - struct #raw_params { 75 - #(#struct_def_params,)* 76 - } 77 - 78 - impl #raw_params { 79 - fn get_field_names() -> Vec<&'static str> { 80 - vec![#(stringify!(#struct_def_params)),*] 70 + impl maudit::page::InternalPage for #struct_name { 71 + fn route_type(&self) -> maudit::page::RouteType { 72 + #route_type 81 73 } 82 - } 83 74 84 - impl maudit::page::InternalPage for #struct_name { 85 75 fn route_raw(&self) -> String { 86 76 #path.to_string() 87 77 } ··· 106 96 let params = params.into(); 107 97 108 98 // Check that the params refer to a page that exists 109 - let all_routes = self::DynamicPage::routes(self, dynamic_route_context); 99 + let all_routes = self::DynamicRoute::routes(self, dynamic_route_context); 110 100 let mut found = false; 111 101 112 102 for route in all_routes {