This commit is contained in:
parent
0147c599a8
commit
a1b2ece601
|
@ -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) {
|
func simplifyCardFromProperties(card microsub.Card, hcard map[string]interface{}) (microsub.Card, bool) {
|
||||||
for ik, vk := range hcard {
|
for ik, vk := range hcard {
|
||||||
if arr, ok := vk.([]interface{}); ok {
|
switch ik {
|
||||||
switch ik {
|
case "type":
|
||||||
case "type":
|
if arr, ok := vk.([]interface{}); ok {
|
||||||
if p, ok := arr[0].(string); ok {
|
if p, ok := arr[0].(string); ok {
|
||||||
card.Type = p[2:]
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,3 +182,20 @@ func TestConvert992(t *testing.T) {
|
||||||
assert.Equal(t, "card", author.Type)
|
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
37
pkg/jf2/tests/author.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user