Allow empty content

master
Jan-Lukas Else 2020-01-12 17:30:32 +01:00
parent 2136265825
commit f71738cde4
1 changed files with 68 additions and 72 deletions

140
entry.go
View File

@ -79,87 +79,83 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") { if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") {
return nil, errors.New("only entry type is supported so far") return nil, errors.New("only entry type is supported so far")
} }
if _, ok := values["content"]; ok { entry := &Entry{}
entry := &Entry{ if content, ok := values["content"]; ok {
content: values["content"][0], entry.content = content[0]
}
if name, ok := values["name"]; ok {
entry.title = name[0]
}
if category, ok := values["category"]; ok {
entry.tags = category
} else if categories, ok := values["category[]"]; ok {
entry.tags = categories
} else {
entry.tags = nil
}
if slug, ok := values["mp-slug"]; ok && len(slug) > 0 && slug[0] != "" {
entry.slug = slug[0]
}
if inReplyTo, ok := values["in-reply-to"]; ok {
entry.replyLink = inReplyTo[0]
}
if likeOf, ok := values["like-of"]; ok {
entry.likeLink = likeOf[0]
}
if bookmarkOf, ok := values["bookmark-of"]; ok {
entry.link = bookmarkOf[0]
}
if syndicate, ok := values["mp-syndicate-to"]; ok {
entry.syndicate = syndicate
} else if syndicates, ok := values["mp-syndicate-to[]"]; ok {
entry.syndicate = syndicates
} else {
entry.syndicate = nil
}
if token, ok := values["access_token"]; ok {
entry.token = "Bearer " + token[0]
}
err := computeExtraSettings(entry)
if err != nil {
return nil, err
}
return entry, nil
} }
return nil, errors.New("error parsing the entry") if name, ok := values["name"]; ok {
entry.title = name[0]
}
if category, ok := values["category"]; ok {
entry.tags = category
} else if categories, ok := values["category[]"]; ok {
entry.tags = categories
} else {
entry.tags = nil
}
if slug, ok := values["mp-slug"]; ok && len(slug) > 0 && slug[0] != "" {
entry.slug = slug[0]
}
if inReplyTo, ok := values["in-reply-to"]; ok {
entry.replyLink = inReplyTo[0]
}
if likeOf, ok := values["like-of"]; ok {
entry.likeLink = likeOf[0]
}
if bookmarkOf, ok := values["bookmark-of"]; ok {
entry.link = bookmarkOf[0]
}
if syndicate, ok := values["mp-syndicate-to"]; ok {
entry.syndicate = syndicate
} else if syndicates, ok := values["mp-syndicate-to[]"]; ok {
entry.syndicate = syndicates
} else {
entry.syndicate = nil
}
if token, ok := values["access_token"]; ok {
entry.token = "Bearer " + token[0]
}
err := computeExtraSettings(entry)
if err != nil {
return nil, err
}
return entry, nil
} }
func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) { func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) {
if len(mfEntry.Type) != 1 || mfEntry.Type[0] != "h-entry" { if len(mfEntry.Type) != 1 || mfEntry.Type[0] != "h-entry" {
return nil, errors.New("only entry type is supported so far") return nil, errors.New("only entry type is supported so far")
} }
entry := &Entry{}
if mfEntry.Properties != nil && len(mfEntry.Properties.Content) == 1 && len(mfEntry.Properties.Content[0]) > 0 { if mfEntry.Properties != nil && len(mfEntry.Properties.Content) == 1 && len(mfEntry.Properties.Content[0]) > 0 {
entry := &Entry{ entry.content = mfEntry.Properties.Content[0]
content: mfEntry.Properties.Content[0],
}
if len(mfEntry.Properties.Name) == 1 {
entry.title = mfEntry.Properties.Name[0]
}
if len(mfEntry.Properties.Category) > 0 {
entry.tags = mfEntry.Properties.Category
}
if len(mfEntry.Properties.MpSlug) == 1 && len(mfEntry.Properties.MpSlug[0]) > 0 {
entry.slug = mfEntry.Properties.MpSlug[0]
}
if len(mfEntry.Properties.InReplyTo) == 1 {
entry.replyLink = mfEntry.Properties.InReplyTo[0]
}
if len(mfEntry.Properties.LikeOf) == 1 {
entry.likeLink = mfEntry.Properties.LikeOf[0]
}
if len(mfEntry.Properties.BookmarkOf) == 1 {
entry.link = mfEntry.Properties.BookmarkOf[0]
}
if len(mfEntry.Properties.MpSyndicateTo) > 0 {
entry.syndicate = mfEntry.Properties.MpSyndicateTo
}
err := computeExtraSettings(entry)
if err != nil {
return nil, err
}
return entry, nil
} }
return nil, errors.New("error parsing the entry") if len(mfEntry.Properties.Name) == 1 {
entry.title = mfEntry.Properties.Name[0]
}
if len(mfEntry.Properties.Category) > 0 {
entry.tags = mfEntry.Properties.Category
}
if len(mfEntry.Properties.MpSlug) == 1 && len(mfEntry.Properties.MpSlug[0]) > 0 {
entry.slug = mfEntry.Properties.MpSlug[0]
}
if len(mfEntry.Properties.InReplyTo) == 1 {
entry.replyLink = mfEntry.Properties.InReplyTo[0]
}
if len(mfEntry.Properties.LikeOf) == 1 {
entry.likeLink = mfEntry.Properties.LikeOf[0]
}
if len(mfEntry.Properties.BookmarkOf) == 1 {
entry.link = mfEntry.Properties.BookmarkOf[0]
}
if len(mfEntry.Properties.MpSyndicateTo) > 0 {
entry.syndicate = mfEntry.Properties.MpSyndicateTo
}
err := computeExtraSettings(entry)
if err != nil {
return nil, err
}
return entry, nil
} }
func computeExtraSettings(entry *Entry) error { func computeExtraSettings(entry *Entry) error {