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,10 +203,22 @@ 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 {
// Strip HTML as we want to get plain text. var description string
description, err := html2text.FromString(article.Description)
if err != nil { // Some feeds don't provide a description, let's use the content
return "", err // in this case, otherwise use the shorter description.
if article.Description != "" {
// Strip HTML as we want to get plain text.
description, err = html2text.FromString(article.Description)
if err != nil {
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.
@ -216,7 +228,12 @@ 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 {
description = description + line + "\n" l := len(line)
println("Fragment: ", line, l)
// Only if the only content is not "> ", thank you reddit.
if line != "> " {
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).