Fix author simplifcation
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2019-02-08 23:39:43 +01:00
parent 0147c599a8
commit a1b2ece601
Signed by: peter
GPG Key ID: 374322D56E5209E8
3 changed files with 63 additions and 9 deletions

View File

@ -240,19 +240,19 @@ func simplifyCardFromProperties2(card *microsub.Card, properties map[string]inte
func simplifyCardFromProperties(card microsub.Card, hcard map[string]interface{}) (microsub.Card, bool) {
for ik, vk := range hcard {
if arr, ok := vk.([]interface{}); ok {
switch ik {
case "type":
switch ik {
case "type":
if arr, ok := vk.([]interface{}); ok {
if p, ok := arr[0].(string); ok {
card.Type = p[2:]
}
case "properties":
if p, ok := arr[0].(map[string]interface{}); ok {
simplifyCardFromProperties2(&card, p)
}
default:
log.Printf("In simplifyCardFromProperties: unknown property %q with value %q\n", ik, arr[0])
}
case "properties":
if p, ok := vk.(map[string]interface{}); ok {
simplifyCardFromProperties2(&card, p)
}
default:
log.Printf("In simplifyCardFromProperties: unknown property %q with value %q\n", ik, vk)
}
}

View File

@ -182,3 +182,20 @@ func TestConvert992(t *testing.T) {
assert.Equal(t, "card", author.Type)
}
}
func TestConvertAuthor(t *testing.T) {
var mdItem microformats.Data
f, err := os.Open("tests/author.json")
if err != nil {
t.Fatalf("error while opening author.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, "Testing NODE RED", item.Name)
assert.Equal(t, "Hello world", item.Content.Text)
assert.Equal(t, "Peter Stuifzand", item.Author.Name)
}
}

37
pkg/jf2/tests/author.json Normal file
View File

@ -0,0 +1,37 @@
{
"items": [
{
"type": [
"h-entry"
],
"properties": {
"author": [
{
"type": [
"h-card"
],
"properties": {
"name": [
"Peter Stuifzand"
],
"url": [
"https://p83.nl"
],
"photo": [
"https://peterstuifzand.nl/img/profile.jpg"
]
}
}
],
"name": [
"Testing NODE RED"
],
"content": [
{
"value": "Hello world"
}
]
}
}
]
}