Skip to content

Commit

Permalink
feat(ptd): add support for new types
Browse files Browse the repository at this point in the history
new supported types: recipe, review, audio,
bookmark, follow, and checkin.
  • Loading branch information
hacdias authored and willnorris committed Dec 14, 2023
1 parent 2310c0e commit 07cd52d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 15 additions & 2 deletions ptd/ptd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
}
}

Expand All @@ -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"
}
Expand Down Expand Up @@ -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"
}
Expand Down
21 changes: 18 additions & 3 deletions ptd/ptd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ func Test_NilItems(t *testing.T) {
}

func Test_PostType_Type(t *testing.T) {
item := &microformats.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 := &microformats.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)
}
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 07cd52d

Please sign in to comment.