Skip to content

Commit

Permalink
Fix: add nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepla committed Jun 2, 2022
1 parent c83307c commit 3a5e3d9
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions ui/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ import (
)

func renderPreviewWindow(item *gofeed.Item) string {
var author string
if item.Author != nil {
author = item.Author.Name
}
var publishedAt string
if item.PublishedParsed != nil {
publishedAt = humanizeTime(item.PublishedParsed)
} else {
publishedAt = item.Published
}
var updatedAt string
if item.UpdatedParsed != nil {
updatedAt = humanizeTime(item.UpdatedParsed)
} else {
updatedAt = item.Updated
}
author := func() string {
if item.Author != nil {
return item.Author.Name
}
return ""
}()
publishedAt := func() string {
if item.PublishedParsed != nil {
return humanizeTime(item.PublishedParsed)
}
return item.Published
}()
updatedAt := func() string {
if item.UpdatedParsed != nil {
return humanizeTime(item.UpdatedParsed)
}
return item.Updated
}()
return fmt.Sprintf(
"β–  %s\n\n %s\n\n %s %s\n\n%s\n",
item.Title,
Expand All @@ -36,22 +38,24 @@ func renderPreviewWindow(item *gofeed.Item) string {
}

func renderContent(item *gofeed.Item) string {
var author string
if item.Author != nil {
sprintfIfNotEmpty("by %s ", item.Author.Name)
}
var publishedAt string
if item.PublishedParsed != nil {
publishedAt = humanizeTime(item.PublishedParsed)
} else {
publishedAt = item.Published
}
var updatedAt string
if item.UpdatedParsed != nil {
updatedAt = humanizeTime(item.UpdatedParsed)
} else {
updatedAt = item.Updated
}
author := func() string {
if item.Author != nil {
return item.Author.Name
}
return ""
}()
publishedAt := func() string {
if item.PublishedParsed != nil {
return humanizeTime(item.PublishedParsed)
}
return item.Published
}()
updatedAt := func() string {
if item.UpdatedParsed != nil {
return humanizeTime(item.UpdatedParsed)
}
return item.Updated
}()
return fmt.Sprintf(
`%s%s %s
──────
Expand Down

0 comments on commit 3a5e3d9

Please sign in to comment.