Improve author handling
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2018-08-05 22:44:42 +02:00
parent 41c079b871
commit dc7493737a
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -69,12 +69,14 @@ func simplify(itemType string, item map[string][]interface{}) map[string]interfa
} else if k == "featured" { } else if k == "featured" {
feedItem[k] = v feedItem[k] = v
} else if k == "checkin" || k == "author" { } else if k == "checkin" || k == "author" {
if value, ok := v[0].(string); ok {
feedItem[k] = value
}
card, err := simplifyCard(v) card, err := simplifyCard(v)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
continue continue
} }
feedItem[k] = card feedItem[k] = card
} else if value, ok := v[0].(*microformats.Microformat); ok { } else if value, ok := v[0].(*microformats.Microformat); ok {
mType := value.Type[0][2:] mType := value.Type[0][2:]
@ -168,30 +170,24 @@ func SimplifyMicroformatData(md *microformats.Data) []map[string]interface{} {
return items return items
} }
func MapToAuthor(result map[string]string) *microsub.Card { func fetchValue(key string, values map[string]interface{}) string {
if value, e := values[key]; e {
if stringValue, ok:= value.(string); ok {
return stringValue
}
}
return ""
}
func MapToAuthor(result map[string]interface{}) *microsub.Card {
item := &microsub.Card{} item := &microsub.Card{}
item.Type = "card" item.Type = "card"
if name, e := result["name"]; e { item.Name = fetchValue("name", result);
item.Name = name item.URL = fetchValue("url", result);
} item.Photo = fetchValue("photo", result);
if u, e := result["url"]; e { item.Longitude = fetchValue("longitude", result);
item.URL = u item.Latitude = fetchValue("latitude", result);
} item.CountryName = fetchValue("country-name", result);
if photo, e := result["photo"]; e { item.Locality = fetchValue("locality", result);
item.Photo = photo
}
if value, e := result["longitude"]; e {
item.Longitude = value
}
if value, e := result["latitude"]; e {
item.Latitude = value
}
if value, e := result["country-name"]; e {
item.CountryName = value
}
if value, e := result["locality"]; e {
item.Locality = value
}
return item return item
} }
@ -216,12 +212,16 @@ func MapToItem(result map[string]interface{}) microsub.Item {
item.UID = uid.(string) item.UID = uid.(string)
} }
if author, e := result["author"]; e { if authorValue, e := result["author"]; e {
item.Author = MapToAuthor(author.(map[string]string)) if author, ok := authorValue.(map[string]interface{}); ok {
item.Author = MapToAuthor(author)
}
} }
if checkin, e := result["checkin"]; e { if checkinValue, e := result["checkin"]; e {
item.Checkin = MapToAuthor(checkin.(map[string]string)) if checkin, ok := checkinValue.(map[string]interface{}); ok {
item.Checkin = MapToAuthor(checkin)
}
} }
if refsValue, e := result["refs"]; e { if refsValue, e := result["refs"]; e {