From efe8f1a549486d07a6f9df99ba561925238f982f Mon Sep 17 00:00:00 2001 From: mdosch Date: Sun, 26 May 2019 21:03:02 +0200 Subject: [PATCH] Made some changes to remove multiple linebreaks and (hopefully) made help output look more nice. Revert "Revert "(Hopefully) made help output look more nice."" This reverts commit b73f39ef4846537c0a2ba1a7997937c471cd16b3. --- feed-to-muc.go | 4 ++-- getarticles.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/feed-to-muc.go b/feed-to-muc.go index ec32ef4..17dcf1c 100644 --- a/feed-to-muc.go +++ b/feed-to-muc.go @@ -251,8 +251,8 @@ func processStanzas(client *xmpp.Client, muc string, mucNick string, feeds []str _, err = client.Send(xmpp.Chat{Remote: muc, Type: "groupchat", Text: strings.Split(v.Remote, "/")[1] + ": The following commands are available:\n" + - "feeds\t" + "List feeds I'm following.\n" + - "source\t" + "Show source code URL."}) + "feeds " + "List feeds I'm following.\n" + + "source " + "Show source code URL."}) if err != nil { log.Fatal(err) } diff --git a/getarticles.go b/getarticles.go index aa906a3..6ea90ac 100644 --- a/getarticles.go +++ b/getarticles.go @@ -209,13 +209,23 @@ func getArticles(feedURL string, max int, noExcerpt bool) (string, error) { return "", err } + // To make the message look not so bloated we remove multiple newlines. + // Split the article description/content into fragments between newlines. + fragments := strings.Split(description, "\n") + // Empty article description/content + description = "" + // Fill article description/content with the fragments separated by one newline. + for _, line := range fragments { + description = description + line + "n" + } + // Only append article link if it is not yet contained in description (e.g. read more: URL). if strings.Contains(description, article.Link) == true { // Replace article link with URL cleaned from redirects and trackers. description = strings.Replace(description, article.Link, cleanURL, -1) output = output + feed.Title + ": *" + article.Title + "*\n\n" + description } else { - output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + "\n" + cleanURL + output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + cleanURL } }