From 52605f18b6876431fd226ed3127dc4c5dc669ff3 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 23 May 2022 16:05:19 +0300 Subject: 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). --- templates/src/lib.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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::(); + + 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::(); + + 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) -- cgit 1.4.1