From f75cc73b8b7874d2125ce0b9ec2b650f9022a255 Mon Sep 17 00:00:00 2001 From: Jeff Kaufman Date: Tue, 18 Jun 2019 22:29:31 -0400 Subject: [PATCH] improve handling of feeds with no summary When testing Openring with Atom feeds like http://blog.davidchudzicki.com/feeds/posts/default and http://www.givinggladly.com/feeds/posts/default I noticed it wasn't able to pull out a text snippet. Falling back to Content if Summary is null fixes this. Content is html encoded, however, which means that we also need an UnescapeString or else Sanitize won't remove the HTML tags. --- openring.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openring.go b/openring.go index 7ea5b91..8c7ffdb 100644 --- a/openring.go +++ b/openring.go @@ -1,6 +1,7 @@ package main import ( + "html" "html/template" "io/ioutil" "log" @@ -114,8 +115,12 @@ func main() { items = items[:perSource] } for _, item := range items { + raw_summary := item.Summary + if len(raw_summary) == 0 { + raw_summary = html.UnescapeString(item.Content) + } summary := runewidth.Truncate( - policy.Sanitize(item.Summary), summaryLen, "…") + policy.Sanitize(raw_summary), summaryLen, "…") articles = append(articles, &Article{ Date: item.Date, SourceLink: feed.Link,