Added a detection for empty descriptions to use content instead. Also added a workaround for broken fdroid reddit feed (empty citation lines).

This commit is contained in:
mdosch 2019-05-26 22:28:58 +02:00
parent bd57fc34d4
commit 576c259d60

View file

@ -203,11 +203,23 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
output = output + feed.Title + ": *" + article.Title + "*\n" + output = output + feed.Title + ": *" + article.Title + "*\n" +
cleanURL cleanURL
} else { } else {
var description string
// Some feeds don't provide a description, let's use the content
// in this case, otherwise use the shorter description.
if article.Description != "" {
// Strip HTML as we want to get plain text. // Strip HTML as we want to get plain text.
description, err := html2text.FromString(article.Description) description, err = html2text.FromString(article.Description)
if err != nil { if err != nil {
return "", err return "", err
} }
} else {
// Strip HTML as we want to get plain text.
description, err = html2text.FromString(article.Content)
if err != nil {
return "", err
}
}
// To make the message look not so bloated we remove multiple newlines. // To make the message look not so bloated we remove multiple newlines.
// Split the article description/content into fragments between newlines. // Split the article description/content into fragments between newlines.
@ -216,8 +228,13 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) {
description = "" description = ""
// Fill article description/content with the fragments separated by one newline. // Fill article description/content with the fragments separated by one newline.
for _, line := range fragments { for _, line := range fragments {
l := len(line)
println("Fragment: ", line, l)
// Only if the only content is not "> ", thank you reddit.
if line != "> " {
description = description + line + "\n" description = description + line + "\n"
} }
}
// Only append article link if it is not yet contained in description (e.g. read more: URL). // Only append article link if it is not yet contained in description (e.g. read more: URL).
if strings.Contains(description, article.Link) == true { if strings.Contains(description, article.Link) == true {