Rust library to generate static websites
5
fork

Configure Feed

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

nit: rename some APIs

+15 -8
+4 -4
crates/framework/src/content.rs
··· 29 29 Self(collections) 30 30 } 31 31 32 - pub fn get_untyped_collection(&self, name: &str) -> &ContentSource<Untyped> { 32 + pub fn get_untyped_source(&self, name: &str) -> &ContentSource<Untyped> { 33 33 self.0 34 34 .iter() 35 35 .find_map( ··· 41 41 .unwrap_or_else(|| panic!("Collection with name '{}' not found", name)) 42 42 } 43 43 44 - pub fn get_untyped_collection_safe(&self, name: &str) -> Option<&ContentSource<Untyped>> { 44 + pub fn get_untyped_source_safe(&self, name: &str) -> Option<&ContentSource<Untyped>> { 45 45 self.0.iter().find_map(|source| { 46 46 match source.as_any().downcast_ref::<ContentSource<Untyped>>() { 47 47 Some(source) if source.name == name => Some(source), ··· 50 50 }) 51 51 } 52 52 53 - pub fn get_collection<T: 'static>(&self, name: &str) -> &ContentSource<T> { 53 + pub fn get_source<T: 'static>(&self, name: &str) -> &ContentSource<T> { 54 54 self.0 55 55 .iter() 56 56 .find_map( ··· 62 62 .unwrap_or_else(|| panic!("Collection with name '{}' not found", name)) 63 63 } 64 64 65 - pub fn get_collection_safe<T: 'static>(&self, name: &str) -> Option<&ContentSource<T>> { 65 + pub fn get_source_safe<T: 'static>(&self, name: &str) -> Option<&ContentSource<T>> { 66 66 self.0.iter().find_map( 67 67 |source| match source.as_any().downcast_ref::<ContentSource<T>>() { 68 68 Some(source) if source.name == name => Some(source),
+8 -1
crates/framework/src/lib.rs
··· 124 124 return writeln!(buf, "{}", record.args()); 125 125 } 126 126 127 + // TODO: Add different formatting for warn, error, etc. 128 + 127 129 writeln!( 128 130 buf, 129 131 "{} {} {}", ··· 229 231 page::RouteType::Dynamic => { 230 232 let routes = route.routes(&dynamic_route_context); 231 233 232 - info!(target: "build", "{}", route.route_raw().to_string().bold()); 234 + if routes.is_empty() { 235 + info!(target: "build", "{} is a registered dynamic route, but it returned no routes. No pages will be generated for this route.", route.route_raw().to_string().bold()); 236 + continue; 237 + } else { 238 + info!(target: "build", "{}", route.route_raw().to_string().bold()); 239 + } 233 240 234 241 for params in routes { 235 242 let mut pages_assets = assets::PageAssets {
+3 -3
examples/blog/src/pages/article.rs
··· 10 10 pub article: String, 11 11 } 12 12 13 - impl DynamicPage for Article { 13 + impl DynamicRoute for Article { 14 14 fn routes(&self, ctx: &DynamicRouteContext) -> Vec<RouteParams> { 15 - let collection = ctx.content.get_collection::<ArticleContent>("articles"); 15 + let collection = ctx.content.get_source::<ArticleContent>("articles"); 16 16 17 17 collection.into_params(|entry| ArticleParams { 18 18 article: entry.id.clone(), ··· 23 23 impl Page for Article { 24 24 fn render(&self, ctx: &mut RouteContext) -> RenderResult { 25 25 let params = ctx.params::<ArticleParams>(); 26 - let articles = ctx.content.get_collection::<ArticleContent>("articles"); 26 + let articles = ctx.content.get_source::<ArticleContent>("articles"); 27 27 let article = articles.get_entry(&params.article); 28 28 29 29 layout((article.render)()).into()