From 20867384e36fba1d33113dbdbb0bdd94aabf6760 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 23 May 2022 18:19:39 +0300 Subject: templates: render like and bookmark posts correctly They really use the same framework, so for now a unit test for like posts is sufficient. Of course, for proper coverage, one can introduce tests for bookmarks too, especially if one chooses to render them differently. The logic will be pretty much the same though. Replies might use the same logic, since those are also Webmention-oriented posts. (It looks like another way to classify MF2 documents is slowly forming in my brain. Maybe I should write about it on my blog.) --- templates/src/templates.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'templates/src/templates.rs') diff --git a/templates/src/templates.rs b/templates/src/templates.rs index f2040fc..66edc9a 100644 --- a/templates/src/templates.rs +++ b/templates/src/templates.rs @@ -77,6 +77,55 @@ markup::define! { } } Entry<'a>(post: &'a serde_json::Value) { + @if post.pointer("/properties/like-of").is_none() && post.pointer("/properties/bookmark-of").is_none() { + @FullEntry { post } + } else { + // Show a mini-post. + @MiniEntry { post } + } + } + MiniEntry<'a>(post: &'a serde_json::Value) { + article."h-entry mini-entry" { + @if let Some(author) = post["properties"]["author"][0].as_object() { + span."mini-h-card"."u-author" { + a."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() + } + } + @if let Some(likeof) = post["properties"]["like-of"][0].as_str() { + " ❤️ " + a."u-like-of"[href=likeof] { @likeof } + } else if let Some(likeof) = post["properties"]["like-of"][0].as_object() { + a."u-like-of"[href=likeof["properties"]["url"][0].as_str().unwrap()] { + @likeof["properties"]["name"][0] + .as_str() + .unwrap_or_else(|| likeof["properties"]["url"][0].as_str().unwrap()) + } + } + @if let Some(bookmarkof) = post["properties"]["bookmark-of"][0].as_str() { + " 🔖 " + a."u-bookmark-of"[href=bookmarkof] { @bookmarkof } + } else if let Some(bookmarkof) = post["properties"]["bookmark-of"][0].as_object() { + a."u-bookmark-of"[href=bookmarkof["properties"]["url"][0].as_str().unwrap()] { + @bookmarkof["properties"]["name"][0] + .as_str() + .unwrap_or_else(|| bookmarkof["properties"]["url"][0].as_str().unwrap()) + } + } + @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("on %a %b %e %T %Y").to_string()) + .unwrap_or("sometime in the past".to_string()) + } + } + } + } + } + FullEntry<'a>(post: &'a serde_json::Value) { article."h-entry" { header.metadata { @if let Some(name) = post["properties"]["name"][0].as_str() { -- cgit 1.4.1