Rust library to generate static websites
5
fork

Configure Feed

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

fix: misc

+30 -25
+4 -4
crates/maudit-macros/src/lib.rs
··· 201 201 // Generate route_raw implementation based on whether path is provided 202 202 let route_raw_impl = if let Some(path) = &args.path { 203 203 quote! { 204 - fn route_raw(&self) -> String { 205 - #path.to_string() 204 + fn route_raw(&self) -> Option<String> { 205 + Some(#path.to_string()) 206 206 } 207 207 } 208 208 } else { 209 209 quote! { 210 - fn route_raw(&self) -> String { 211 - String::new() 210 + fn route_raw(&self) -> Option<String> { 211 + None 212 212 } 213 213 } 214 214 };
+7 -7
crates/maudit/src/build.rs
··· 132 132 let base_path = route.route_raw(); 133 133 let variants = cached_route.variants(); 134 134 135 - trace!(target: "build", "Processing route: base='{}', variants={}", base_path, variants.len()); 135 + trace!(target: "build", "Processing route: base='{}', variants={}", base_path.as_deref().unwrap_or(""), variants.len()); 136 136 137 - let has_base_route = !base_path.is_empty(); 137 + let has_base_route = base_path.is_some(); 138 138 139 139 if !has_base_route && !variants.is_empty() { 140 140 info!(target: "pages", "(variants only)"); 141 141 } 142 142 143 143 // Handle base route 144 - if has_base_route { 145 - let base_params = extract_params_from_raw_route(&base_path); 144 + if let Some(ref base_path) = base_path { 145 + let base_params = extract_params_from_raw_route(base_path); 146 146 147 147 // Static base route 148 148 if base_params.is_empty() { ··· 260 260 build_pages_styles.extend(route_assets.styles); 261 261 262 262 build_metadata.add_page( 263 - format!("{} ({})", base_path, variant_id), 263 + variant_path.clone(), 264 264 file_path.to_string_lossy().to_string(), 265 265 None, 266 266 ); ··· 306 306 info!(target: "pages", "│ ├─ {} {}", file_path.to_string_lossy().dimmed(), format_elapsed_time(variant_page_start.elapsed(), &route_format_options)); 307 307 308 308 build_metadata.add_page( 309 - route.route_raw().to_string(), 309 + variant_path.clone(), 310 310 file_path.to_string_lossy().to_string(), 311 - Some(page.0.0), 311 + Some(page.0.0.clone()), 312 312 ); 313 313 314 314 page_count += 1;
+19 -14
crates/maudit/src/route.rs
··· 470 470 /// Used internally by Maudit and should not be implemented by the user. 471 471 /// We expose it because the derive macro implements it for the user behind the scenes. 472 472 pub trait InternalRoute { 473 - fn route_raw(&self) -> String; 473 + fn route_raw(&self) -> Option<String>; 474 474 475 475 fn variants(&self) -> Vec<(String, String)> { 476 476 vec![] 477 477 } 478 478 479 479 fn is_endpoint(&self) -> bool { 480 - guess_if_route_is_endpoint(&self.route_raw()) 480 + self.route_raw() 481 + .as_ref() 482 + .map(|path| guess_if_route_is_endpoint(path)) 483 + .unwrap_or(false) 481 484 } 482 485 483 486 #[deprecated] 484 487 fn route_type(&self) -> RouteType { 485 - let params_def = extract_params_from_raw_route(&self.route_raw()); 488 + let path = self.route_raw().unwrap_or_default(); 489 + let params_def = extract_params_from_raw_route(&path); 486 490 487 491 // Check if base route is dynamic 488 492 if !params_def.is_empty() { ··· 502 506 } 503 507 504 508 fn url(&self, params: &PageParams) -> String { 505 - let route = self.route_raw(); 509 + let route = self.route_raw().unwrap_or_default(); 506 510 let params_def = extract_params_from_raw_route(&route); 507 511 build_url_with_params(&route, &params_def, params, self.is_endpoint()) 508 512 } ··· 525 529 } 526 530 527 531 fn file_path(&self, params: &PageParams, output_dir: &Path) -> PathBuf { 528 - let route = self.route_raw(); 532 + let route = self.route_raw().unwrap_or_default(); 529 533 let params_def = extract_params_from_raw_route(&route); 530 534 build_file_path_with_params(&route, &params_def, params, output_dir, self.is_endpoint()) 531 535 } ··· 606 610 607 611 fn build(&self, ctx: &mut PageContext) -> Result<Vec<u8>, Box<dyn std::error::Error>> { 608 612 let result = self.render_internal(ctx)?; 609 - let bytes = finish_route(result, ctx.assets, self.route_raw())?; 613 + let bytes = finish_route(result, ctx.assets, self.route_raw().unwrap_or_default())?; 610 614 611 615 Ok(bytes) 612 616 } ··· 725 729 } 726 730 727 731 fn get_cached_params(&self) -> &Vec<ParameterDef> { 728 - self.params_cache 729 - .get_or_init(|| extract_params_from_raw_route(&self.inner.route_raw())) 732 + self.params_cache.get_or_init(|| { 733 + extract_params_from_raw_route(&self.inner.route_raw().unwrap_or_default()) 734 + }) 730 735 } 731 736 732 737 fn is_endpoint(&self) -> bool { 733 738 *self 734 739 .is_endpoint 735 - .get_or_init(|| guess_if_route_is_endpoint(&self.inner.route_raw())) 740 + .get_or_init(|| guess_if_route_is_endpoint(&self.inner.route_raw().unwrap_or_default())) 736 741 } 737 742 738 743 fn get_variant_cache(&self, variant_id: &str) -> Option<&(Vec<ParameterDef>, bool)> { ··· 751 756 } 752 757 753 758 impl<'a> InternalRoute for CachedRoute<'a> { 754 - fn route_raw(&self) -> String { 759 + fn route_raw(&self) -> Option<String> { 755 760 self.inner.route_raw() 756 761 } 757 762 ··· 780 785 781 786 fn url(&self, params: &PageParams) -> String { 782 787 build_url_with_params( 783 - &self.route_raw(), 788 + &self.route_raw().unwrap_or_default(), 784 789 self.get_cached_params(), 785 790 params, 786 791 self.is_endpoint(), ··· 807 812 808 813 fn file_path(&self, params: &PageParams, output_dir: &Path) -> PathBuf { 809 814 build_file_path_with_params( 810 - &self.route_raw(), 815 + &self.route_raw().unwrap_or_default(), 811 816 self.get_cached_params(), 812 817 params, 813 818 output_dir, ··· 939 944 } 940 945 941 946 impl InternalRoute for TestPage { 942 - fn route_raw(&self) -> String { 943 - self.route.clone() 947 + fn route_raw(&self) -> Option<String> { 948 + Some(self.route.clone()) 944 949 } 945 950 } 946 951