diff --git a/README.md b/README.md index f2b2aeb..c705194 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ If the flag `-config` is not used the configuration is expected at "Muc": "muc-to-feed@conference.example.com", "MucNick": "feedbot", "MaxArticles": 5, +"NoExcerpt": false, "Feeds": [ "https://www.debian.org/News/news", "https://www.debian.org/security/dsa-long" ] } diff --git a/config.json.example b/config.json.example index 79c2fbc..2bd6364 100644 --- a/config.json.example +++ b/config.json.example @@ -5,6 +5,7 @@ "Muc": "muc-to-feed@conference.example.com", "MucNick": "feedbot", "MaxArticles": 5, +"NoExcerpt": false, "Feeds": [ "https://www.debian.org/News/news", "https://www.debian.org/security/dsa-long" ] } diff --git a/feed-to-muc.go b/feed-to-muc.go index cbd1232..6603262 100644 --- a/feed-to-muc.go +++ b/feed-to-muc.go @@ -36,6 +36,7 @@ func main() { Muc string MucNick string MaxArticles int + NoExcerpt bool Feeds []string } @@ -147,7 +148,7 @@ func main() { // Check all configured feeds for new articles and send // new articles to configured MUC. for i := 0; i < len(config.Feeds); i++ { - output, err := getArticles(config.Feeds[i], config.MaxArticles) + output, err := getArticles(config.Feeds[i], config.MaxArticles, config.NoExcerpt) if err != nil { // Exit if an error occurs checking the feeds. log.Fatal(err) diff --git a/getarticles.go b/getarticles.go index 67b5b1d..5431a68 100644 --- a/getarticles.go +++ b/getarticles.go @@ -18,7 +18,7 @@ import ( ) // Get new articles for specified feed. -func getArticles(feedURL string, max int) (string, error) { +func getArticles(feedURL string, max int, noExcerpt bool) (string, error) { type feedCache struct { LastChange string @@ -194,19 +194,26 @@ func getArticles(feedURL string, max int) (string, error) { // Remove redirects and tracking parameters from URL. cleanURL, _ := removeTracking(article.Link) - // Strip HTML as we want to get plain text. - description, err := html2text.FromString(article.Description) - if err != nil { - return "", err - } - - // 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 + // Only send title and link if option noExcerpt is set, + // otherwise add the description. + if noExcerpt == true { + output = output + feed.Title + ": *" + article.Title + "*\n" + + cleanURL } else { - output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + "\n" + cleanURL + // Strip HTML as we want to get plain text. + description, err := html2text.FromString(article.Description) + if err != nil { + return "", err + } + + // 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 + } } if i > 0 {