diff options
Diffstat (limited to 'templates/src')
-rw-r--r-- | templates/src/templates.rs | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/templates/src/templates.rs b/templates/src/templates.rs index 44e6042..f2040fc 100644 --- a/templates/src/templates.rs +++ b/templates/src/templates.rs @@ -79,29 +79,28 @@ markup::define! { Entry<'a>(post: &'a serde_json::Value) { article."h-entry" { header.metadata { - @if post["properties"]["name"][0].is_string() { - h1."p-name" { - @post["properties"]["name"][0].as_str().unwrap() - } - } else { - @if post["properties"]["author"][0].is_object() { - section."mini-h-card" { - a.larger[href=post["properties"]["author"][0]["properties"]["uid"][0].as_str().unwrap()] { - @if post["properties"]["author"][0]["properties"]["photo"][0].is_string() { - img[src=post["properties"]["author"][0]["properties"]["photo"][0].as_str().unwrap()] {} - } - @post["properties"]["author"][0]["properties"]["name"][0].as_str().unwrap() + @if let Some(name) = post["properties"]["name"][0].as_str() { + h1."p-name" { @name } + } + @if let Some(author) = post["properties"]["author"][0].as_object() { + section."mini-h-card" { + a.larger."u-author"[href=author["properties"]["uid"][0].as_str().unwrap()] { + @if let Some(photo) = author["properties"]["photo"][0].as_str() { + img[src=photo, loading="lazy"]; } + @author["properties"]["name"][0].as_str().unwrap() } } } div { span { a."u-url"."u-uid"[href=post["properties"]["uid"][0].as_str().unwrap()] { - time."dt-published"[datetime=post["properties"]["published"][0].as_str().unwrap()] { - @chrono::DateTime::parse_from_rfc3339(post["properties"]["published"][0].as_str().unwrap()) - .map(|dt| dt.format("%a %b %e %T %Y").to_string()) - .unwrap_or("ERROR: Couldn't parse the datetime".to_string()) + @if let Some(published) = post["properties"]["published"][0].as_str() { + time."dt-published"[datetime=published] { + @chrono::DateTime::parse_from_rfc3339(published) + .map(|dt| dt.format("%a %b %e %T %Y").to_string()) + .unwrap_or("sometime in the past".to_string()) + } } } } @@ -239,17 +238,23 @@ markup::define! { } } PhotoGallery<'a>(photos: Option<&'a Vec<serde_json::Value>>) { - @if photos.is_some() { - @for photo in photos.unwrap() { - @if photo.is_string() { - img."u-photo"[src=photo.as_str().unwrap(), loading="lazy"]; - } else if photo.is_array() { - @if photo["thumbnail"].is_string() { + @if let Some(photos) = photos { + @for photo in photos.iter() { + @if let Some(photo) = photo.as_str() { + img."u-photo"[src=photo, loading="lazy"]; + } else if photo.is_object() { + @if let Some(thumbnail) = photo["thumbnail"].as_str() { a."u-photo"[href=photo["value"].as_str().unwrap()] { - img[src=photo["thumbnail"].as_str().unwrap(), loading="lazy", alt=photo["alt"].as_str().unwrap_or("")]; + img[src=thumbnail, + loading="lazy", + alt=photo["alt"].as_str().unwrap_or("") + ]; } } else { - img."u-photo"[src=photo["value"].as_str().unwrap(), loading="lazy", alt=photo["alt"].as_str().unwrap_or("")]; + img."u-photo"[src=photo["value"].as_str().unwrap(), + loading="lazy", + alt=photo["alt"].as_str().unwrap_or("") + ]; } } } |