about summary refs log tree commit diff
path: root/templates/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-05-23 16:05:19 +0300
committerVika <vika@fireburn.ru>2022-05-23 16:05:19 +0300
commit52605f18b6876431fd226ed3127dc4c5dc669ff3 (patch)
tree256b2eca0fbe4e2b22a623597f507cfd35dcfce5 /templates/src
parent84f9508813ac368bdce302db7f3a15bc6fce3fee (diff)
downloadkittybox-52605f18b6876431fd226ed3127dc4c5dc669ff3.tar.zst
templates: more MF2 generators
New generators include:
 - Articles (h-entry with a name)
 - Replies (notes with an in-reply-to)
 - Likes (h-entries with a like-of)

For replies and likes, there are variants with an h-cite (full reply
context) or a link (partial reply context).
Diffstat (limited to 'templates/src')
-rw-r--r--templates/src/lib.rs67
1 files changed, 62 insertions, 5 deletions
diff --git a/templates/src/lib.rs b/templates/src/lib.rs
index 01c69ab..f21ffb3 100644
--- a/templates/src/lib.rs
+++ b/templates/src/lib.rs
@@ -59,8 +59,7 @@ mod tests {
                     "properties": {
                         "content": [html(content)],
                         "published": [dt],
-                        "uid": [&uid],
-                        "url": [&uid],
+                        "uid": [&uid], "url": [&uid],
                         "author": [gen_hcard(domain)]
                     }
                 })
@@ -74,14 +73,68 @@ mod tests {
                     "properties": {
                         "content": [html(content)],
                         "published": [dt],
-                        "uid": [&uid],
-                        "url": [&uid],
+                        "uid": [&uid], "url": [&uid],
                         "author": [gen_hcard(domain)],
                         "name": [name.to_string()]
                     }
                 })
             }
-            _ => todo!()
+            PostType::ReplyTo(ctx) => {
+                let content = rand::random::<Paragraph>();
+
+                json!({
+                    "type": ["h-entry"],
+                    "properties": {
+                        "content": [html(content)],
+                        "published": [dt],
+                        "uid": [&uid], "url": [&uid],
+                        "author": [gen_hcard(domain)],
+                        "in-reply-to": [{
+                            "type": ["h-cite"],
+                            "properties": ctx["properties"]
+                        }]
+                    }
+                })
+            },
+            PostType::ReplyToLink(link) => {
+                let content = rand::random::<Paragraph>();
+
+                json!({
+                    "type": ["h-entry"],
+                    "properties": {
+                        "content": [html(content)],
+                        "published": [dt],
+                        "uid": [&uid], "url": [&uid],
+                        "author": [gen_hcard(domain)],
+                        "in-reply-to": [link]
+                    }
+                })
+            },
+            PostType::LikeOf(ctx) => {
+                json!({
+                    "type": ["h-entry"],
+                    "properties": {
+                        "published": [dt],
+                        "author": [gen_hcard(domain)],
+                        "uid": [&uid], "url": [&uid],
+                        "like-of": [{
+                            "type": ["h-cite"],
+                            "properties": ctx["properties"]
+                        }]
+                    }
+                })
+            },
+            PostType::LikeOfLink(link) => {
+                json!({
+                    "type": ["h-entry"],
+                    "properties": {
+                        "published": [dt],
+                        "author": [gen_hcard(domain)],
+                        "uid": [&uid], "url": [&uid],
+                        "like-of": [link]
+                    }
+                })
+            }
         }
     }
 
@@ -129,6 +182,10 @@ mod tests {
             {
                 use chrono::{DateTime, FixedOffset, NaiveDateTime};
 
+                // Faithfully reconstruct the original datetime
+                // I wonder why not just have an Enum that would
+                // get you either date, time or a datetime,
+                // potentially with an offset?
                 let offset = item.as_offset().unwrap().data;
                 let ndt: NaiveDateTime = item.as_date().unwrap().data
                     .and_time(item.as_time().unwrap().data)