about summary refs log tree commit diff
path: root/templates/src/templates.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-05-23 18:19:39 +0300
committerVika <vika@fireburn.ru>2022-05-23 18:22:07 +0300
commit20867384e36fba1d33113dbdbb0bdd94aabf6760 (patch)
treede8b0ed59e86b5aa1adcf87d9ed6df91c03a7792 /templates/src/templates.rs
parent067d6c4c08120bb9b93190911bd00adf9159bba1 (diff)
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.)
Diffstat (limited to 'templates/src/templates.rs')
-rw-r--r--templates/src/templates.rs49
1 files changed, 49 insertions, 0 deletions
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() {