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

View File

@ -79,9 +79,9 @@ 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 { if name, ok := values["name"]; ok {
entry.title = name[0] entry.title = name[0]
@ -120,17 +120,15 @@ func createEntryFromValueMap(values map[string][]string) (*Entry, error) {
return nil, err return nil, err
} }
return entry, nil return entry, nil
}
return nil, errors.New("error parsing the entry")
} }
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 { if len(mfEntry.Properties.Name) == 1 {
entry.title = mfEntry.Properties.Name[0] entry.title = mfEntry.Properties.Name[0]
@ -158,8 +156,6 @@ func createEntryFromMicroformat(mfEntry *MicroformatItem) (*Entry, error) {
return nil, err return nil, err
} }
return entry, nil return entry, nil
}
return nil, errors.New("error parsing the entry")
} }
func computeExtraSettings(entry *Entry) error { func computeExtraSettings(entry *Entry) error {