This commit is contained in:
parent
5dcb64cc28
commit
9e5601f979
|
@ -19,6 +19,7 @@ package jf2
|
|||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"p83.nl/go/ekster/pkg/microsub"
|
||||
|
||||
|
@ -130,6 +131,13 @@ func simplifyToItem(itemType string, item map[string][]interface{}) microsub.Ite
|
|||
}
|
||||
}
|
||||
|
||||
// Remove "name" when it's equals to "content[text]"
|
||||
if feedItem.Content != nil {
|
||||
if strings.TrimSpace(feedItem.Name) == strings.TrimSpace(feedItem.Content.Text) {
|
||||
feedItem.Name = ""
|
||||
}
|
||||
}
|
||||
|
||||
return feedItem
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"p83.nl/go/ekster/pkg/microsub"
|
||||
"willnorris.com/go/microformats"
|
||||
)
|
||||
|
@ -156,3 +157,28 @@ func TestConvertItem2(t *testing.T) {
|
|||
t.Errorf("Expected Author.Name == %q, was %q", "Peter", item.Author.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvert992(t *testing.T) {
|
||||
var mdItem microformats.Data
|
||||
f, err := os.Open("tests/992.json")
|
||||
if err != nil {
|
||||
t.Fatalf("error while opening 992.json: %s", err)
|
||||
}
|
||||
err = json.NewDecoder(f).Decode(&mdItem)
|
||||
if assert.NoError(t, err) {
|
||||
items := SimplifyMicroformatDataItems(&mdItem)
|
||||
assert.Len(t, items, 1)
|
||||
item := items[0]
|
||||
assert.Equal(t, "https://p83.nl/posts/992", item.URL)
|
||||
assert.Equal(t, "https://p83.nl/posts/992", item.UID)
|
||||
assert.Equal(t, "2018-12-09T14:14:13Z", item.Published)
|
||||
assert.Equal(t, "https://twitter.com/InDeepGeek/status/1071363145485168640", item.LikeOf[0])
|
||||
assert.Equal(t, "entry", item.Type)
|
||||
assert.Equal(t, "", item.Name)
|
||||
assert.Equal(t, "test", item.Content.Text)
|
||||
assert.Equal(t, "<p>test</p>", item.Content.HTML)
|
||||
|
||||
author := item.Author
|
||||
assert.Equal(t, "card", author.Type)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user