~vikanezrimaya/kittybox

52605f18b6876431fd226ed3127dc4c5dc669ff3 — Vika 2 months ago 84f9508
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).
1 files changed, 62 insertions(+), 5 deletions(-)

M templates/src/lib.rs
M templates/src/lib.rs => templates/src/lib.rs +62 -5
@@ 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)