From 07cd52d5def16f9e5f227c803c208fb62a80523f Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 24 Nov 2023 08:30:39 +0100 Subject: [PATCH] feat(ptd): add support for new types new supported types: recipe, review, audio, bookmark, follow, and checkin. --- ptd/ptd.go | 17 +++++++++++++++-- ptd/ptd_test.go | 21 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ptd/ptd.go b/ptd/ptd.go index d6df431..6a92954 100644 --- a/ptd/ptd.go +++ b/ptd/ptd.go @@ -22,8 +22,9 @@ func PostType(item *microformats.Microformat) string { } for _, t := range item.Type { - if t == "h-event" { - return "event" + switch t { + case "h-event", "h-recipe", "h-review": + return t[2:] } } @@ -32,9 +33,15 @@ func PostType(item *microformats.Microformat) string { return t } + if _, ok := item.Properties["checkin"]; ok { + return "checkin" + } if validURL(item.Properties["video"]) { return "video" } + if validURL(item.Properties["audio"]) { + return "audio" + } if validURL(item.Properties["photo"]) { return "photo" } @@ -105,6 +112,12 @@ func ResponseType(item *microformats.Microformat) string { if validURL(item.Properties["in-reply-to"]) { return "reply" } + if validURL(item.Properties["bookmark-of"]) { + return "bookmark" + } + if _, ok := item.Properties["follow-of"]; ok { + return "follow" + } return "mention" } diff --git a/ptd/ptd_test.go b/ptd/ptd_test.go index 846d8d6..d4ee852 100644 --- a/ptd/ptd_test.go +++ b/ptd/ptd_test.go @@ -23,9 +23,20 @@ func Test_NilItems(t *testing.T) { } func Test_PostType_Type(t *testing.T) { - item := µformats.Microformat{Type: []string{"h-event"}} - if got, want := PostType(item), "event"; got != want { - t.Errorf("ResponseType(%v) returned %q, want %q", item, got, want) + tests := []struct { + typ string + want string + }{ + {"h-event", "event"}, + {"h-recipe", "recipe"}, + {"h-review", "review"}, + } + + for _, tt := range tests { + item := µformats.Microformat{Type: []string{tt.typ}} + if got, want := PostType(item), tt.want; got != want { + t.Errorf("ResponseType(%v) returned %q, want %q", item, got, want) + } } } @@ -58,7 +69,11 @@ func Test_PostType_Properties(t *testing.T) { {pm{"in-reply-to": {}}, "note"}, {pm{"in-reply-to": {""}}, "note"}, {pm{"in-reply-to": {"foo"}}, "reply"}, + {pm{"bookmark-of": {"foo"}}, "bookmark"}, + {pm{"follow-of": {"foo"}}, "follow"}, + {pm{"checkin": {"foo"}}, "checkin"}, {pm{"video": {"foo"}}, "video"}, + {pm{"audio": {"foo"}}, "audio"}, {pm{"photo": {"foo"}}, "photo"}, // content and name variations