Rust library to generate static websites
5
fork

Configure Feed

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

fix: logging

+120 -77
+120 -77
crates/maudit/src/build.rs
··· 47 47 url: String, 48 48 /// The output file path 49 49 file_path: PathBuf, 50 - /// Full page result for dynamic routes from get_pages (params, props, typed_params) 50 + /// Full page result for dynamic routes (params, props, typed_params) 51 51 page_result: Option<( 52 52 PageParams, 53 53 crate::route::PageProps, ··· 59 59 tree_depth: usize, 60 60 } 61 61 62 - impl PageToBuild { 62 + /// Represents a route header to log before its pages 63 + struct RouteHeader { 64 + pattern: String, 65 + tree_depth: usize, 66 + } 67 + 68 + enum BuildItem { 69 + Header(RouteHeader), 70 + Page(PageToBuild), 71 + } 72 + 73 + impl BuildItem { 63 74 fn log_prefix(&self) -> &str { 64 - match self.tree_depth { 75 + let tree_depth = match self { 76 + BuildItem::Header(h) => h.tree_depth, 77 + BuildItem::Page(p) => p.tree_depth, 78 + }; 79 + 80 + match tree_depth { 65 81 0 => "", 66 82 1 => "├─ ", 67 83 _ => "│ ├─ ", ··· 161 177 162 178 trace!(target: "build", "Processing route: base='{}', variants={}", base_path, variants.len()); 163 179 164 - // Build list of pages to generate for this route 165 - let mut pages_to_build: Vec<PageToBuild> = Vec::new(); 180 + // Build list of items (headers + pages) to generate for this route 181 + let mut build_items: Vec<BuildItem> = Vec::new(); 182 + 183 + // If no base route but has variants, show "(variants only)" header 184 + if base_path.is_empty() && !variants.is_empty() { 185 + build_items.push(BuildItem::Header(RouteHeader { 186 + pattern: "(variants only)".to_string(), 187 + tree_depth: 0, 188 + })); 189 + } 166 190 167 191 // Handle base route 168 192 if !base_path.is_empty() { 169 193 let base_params = extract_params_from_raw_route(&base_path); 194 + let is_dynamic = !base_params.is_empty(); 195 + 196 + if is_dynamic { 197 + // Add header for dynamic base route 198 + build_items.push(BuildItem::Header(RouteHeader { 199 + pattern: base_path.clone(), 200 + tree_depth: 0, 201 + })); 202 + } 170 203 171 204 if base_params.is_empty() { 172 205 // Static base route ··· 174 207 let url = cached_route.url(&params); 175 208 let file_path = cached_route.file_path(&params, &options.output_dir); 176 209 177 - pages_to_build.push(PageToBuild { 210 + build_items.push(BuildItem::Page(PageToBuild { 178 211 url, 179 212 file_path, 180 213 page_result: None, 181 214 variant_id: None, 182 215 tree_depth: 0, 183 - }); 216 + })); 184 217 } else { 185 218 // Dynamic base route - fetch pages 186 219 let mut page_assets = ··· 194 227 if pages.is_empty() { 195 228 warn!(target: "build", "{} has dynamic parameters but Route::pages returned an empty Vec. No pages will be generated.", base_path.bold()); 196 229 } else { 197 - // Log the pattern first 198 - info!(target: "pages", "{}", base_path); 199 - 200 230 for page in pages { 201 231 let url = cached_route.url(&page.0); 202 232 let file_path = cached_route.file_path(&page.0, &options.output_dir); 203 233 204 - pages_to_build.push(PageToBuild { 234 + build_items.push(BuildItem::Page(PageToBuild { 205 235 url, 206 236 file_path, 207 237 page_result: Some(page), 208 238 variant_id: None, 209 239 tree_depth: 1, 210 - }); 240 + })); 211 241 } 212 242 } 213 243 ··· 220 250 // Handle variants 221 251 for (variant_id, variant_path) in variants { 222 252 let variant_params = extract_params_from_raw_route(&variant_path); 253 + let is_dynamic = !variant_params.is_empty(); 254 + 255 + if is_dynamic { 256 + // Add header for dynamic variant 257 + build_items.push(BuildItem::Header(RouteHeader { 258 + pattern: variant_path.clone(), 259 + tree_depth: 1, 260 + })); 261 + } 223 262 224 263 if variant_params.is_empty() { 225 264 // Static variant ··· 228 267 let file_path = 229 268 cached_route.variant_file_path(&params, &options.output_dir, &variant_id)?; 230 269 231 - pages_to_build.push(PageToBuild { 270 + build_items.push(BuildItem::Page(PageToBuild { 232 271 url, 233 272 file_path, 234 273 page_result: None, 235 274 variant_id: Some(variant_id.clone()), 236 275 tree_depth: 1, 237 - }); 276 + })); 238 277 } else { 239 278 // Dynamic variant - fetch pages 240 279 let mut page_assets = ··· 248 287 if pages.is_empty() { 249 288 warn!(target: "build", "Variant {} has dynamic parameters but Route::pages returned an empty Vec.", variant_id.bold()); 250 289 } else { 251 - // Log the variant pattern first 252 - info!(target: "pages", "├─ {}", variant_path); 253 - 254 290 for page in pages { 255 291 let url = cached_route.variant_url(&page.0, &variant_id)?; 256 292 let file_path = cached_route.variant_file_path( ··· 259 295 &variant_id, 260 296 )?; 261 297 262 - pages_to_build.push(PageToBuild { 298 + build_items.push(BuildItem::Page(PageToBuild { 263 299 url, 264 300 file_path, 265 301 page_result: Some(page), 266 302 variant_id: Some(variant_id.clone()), 267 303 tree_depth: 2, 268 - }); 304 + })); 269 305 } 270 306 } 271 307 ··· 276 312 } 277 313 278 314 // Now build all pages for this route and log as we go 279 - for page_info in pages_to_build { 280 - let mut route_assets = 281 - RouteAssets::new(&route_assets_options, Some(image_cache.clone())); 315 + for build_item in build_items { 316 + match &build_item { 317 + BuildItem::Header(header) => { 318 + info!(target: "pages", "{}{}", build_item.log_prefix(), header.pattern); 319 + } 320 + BuildItem::Page(page_info) => { 321 + let mut route_assets = 322 + RouteAssets::new(&route_assets_options, Some(image_cache.clone())); 282 323 283 - let content = if let Some(ref page_result) = page_info.page_result { 284 - // Build dynamic page 285 - route.build(&mut PageContext::from_dynamic_route( 286 - page_result, 287 - content_sources, 288 - &mut route_assets, 289 - &page_info.url, 290 - &options.base_url, 291 - page_info.variant_id.clone(), 292 - ))? 293 - } else { 294 - // Build static page 295 - route.build(&mut PageContext::from_static_route( 296 - content_sources, 297 - &mut route_assets, 298 - &page_info.url, 299 - &options.base_url, 300 - page_info.variant_id.clone(), 301 - ))? 302 - }; 324 + let content = if let Some(ref page_result) = page_info.page_result { 325 + // Build dynamic page 326 + route.build(&mut PageContext::from_dynamic_route( 327 + page_result, 328 + content_sources, 329 + &mut route_assets, 330 + &page_info.url, 331 + &options.base_url, 332 + page_info.variant_id.clone(), 333 + ))? 334 + } else { 335 + // Build static page 336 + route.build(&mut PageContext::from_static_route( 337 + content_sources, 338 + &mut route_assets, 339 + &page_info.url, 340 + &options.base_url, 341 + page_info.variant_id.clone(), 342 + ))? 343 + }; 303 344 304 - write_route_file(&content, &page_info.file_path)?; 345 + write_route_file(&content, &page_info.file_path)?; 305 346 306 - // Log immediately 307 - let log_line = if page_info.tree_depth == 0 { 308 - format!( 309 - "{} -> {}", 310 - page_info.url, 311 - page_info.file_path.to_string_lossy().dimmed() 312 - ) 313 - } else { 314 - format!( 315 - "{}{}", 316 - page_info.log_prefix(), 317 - page_info.file_path.to_string_lossy().dimmed() 318 - ) 319 - }; 320 - info!(target: "pages", "{}", log_line); 347 + // Log immediately 348 + let log_line = if page_info.tree_depth == 0 && page_info.variant_id.is_none() { 349 + format!( 350 + "{} -> {}", 351 + page_info.url, 352 + page_info.file_path.to_string_lossy().dimmed() 353 + ) 354 + } else { 355 + format!( 356 + "{}{}", 357 + build_item.log_prefix(), 358 + page_info.file_path.to_string_lossy().dimmed() 359 + ) 360 + }; 361 + info!(target: "pages", "{}", log_line); 321 362 322 - // Add to metadata 323 - let metadata_route_name = if let Some(variant_id) = &page_info.variant_id { 324 - if base_path.is_empty() { 325 - format!("({})", variant_id) 326 - } else { 327 - format!("{} ({})", base_path, variant_id) 328 - } 329 - } else { 330 - base_path.clone() 331 - }; 363 + // Add to metadata 364 + let metadata_route_name = if let Some(variant_id) = &page_info.variant_id { 365 + if base_path.is_empty() { 366 + format!("({})", variant_id) 367 + } else { 368 + format!("{} ({})", base_path, variant_id) 369 + } 370 + } else { 371 + base_path.clone() 372 + }; 332 373 333 - build_metadata.add_page( 334 - metadata_route_name, 335 - page_info.file_path.to_string_lossy().to_string(), 336 - page_info.page_result.as_ref().map(|pr| pr.0.0.clone()), 337 - ); 374 + build_metadata.add_page( 375 + metadata_route_name, 376 + page_info.file_path.to_string_lossy().to_string(), 377 + page_info.page_result.as_ref().map(|pr| pr.0.0.clone()), 378 + ); 338 379 339 - build_pages_images.extend(route_assets.images); 340 - build_pages_scripts.extend(route_assets.scripts); 341 - build_pages_styles.extend(route_assets.styles); 380 + build_pages_images.extend(route_assets.images); 381 + build_pages_scripts.extend(route_assets.scripts); 382 + build_pages_styles.extend(route_assets.styles); 342 383 343 - page_count += 1; 384 + page_count += 1; 385 + } 386 + } 344 387 } 345 388 } 346 389