Added config option to post only the article link without excerpt.

This commit is contained in:
Martin Dosch 2018-09-03 20:42:19 +02:00
parent 5a5014d449
commit 7e2c58256d
4 changed files with 24 additions and 14 deletions

View file

@ -45,6 +45,7 @@ If the flag `-config` is not used the configuration is expected at
"Muc": "muc-to-feed@conference.example.com", "Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot", "MucNick": "feedbot",
"MaxArticles": 5, "MaxArticles": 5,
"NoExcerpt": false,
"Feeds": [ "https://www.debian.org/News/news", "Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ] "https://www.debian.org/security/dsa-long" ]
} }

View file

@ -5,6 +5,7 @@
"Muc": "muc-to-feed@conference.example.com", "Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot", "MucNick": "feedbot",
"MaxArticles": 5, "MaxArticles": 5,
"NoExcerpt": false,
"Feeds": [ "https://www.debian.org/News/news", "Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ] "https://www.debian.org/security/dsa-long" ]
} }

View file

@ -36,6 +36,7 @@ func main() {
Muc string Muc string
MucNick string MucNick string
MaxArticles int MaxArticles int
NoExcerpt bool
Feeds []string Feeds []string
} }
@ -147,7 +148,7 @@ func main() {
// Check all configured feeds for new articles and send // Check all configured feeds for new articles and send
// new articles to configured MUC. // new articles to configured MUC.
for i := 0; i < len(config.Feeds); i++ { 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 { if err != nil {
// Exit if an error occurs checking the feeds. // Exit if an error occurs checking the feeds.
log.Fatal(err) log.Fatal(err)

View file

@ -18,7 +18,7 @@ import (
) )
// Get new articles for specified feed. // 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 { type feedCache struct {
LastChange string LastChange string
@ -194,6 +194,12 @@ func getArticles(feedURL string, max int) (string, error) {
// Remove redirects and tracking parameters from URL. // Remove redirects and tracking parameters from URL.
cleanURL, _ := removeTracking(article.Link) cleanURL, _ := removeTracking(article.Link)
// 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 {
// 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 {
@ -208,6 +214,7 @@ func getArticles(feedURL string, max int) (string, error) {
} else { } else {
output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + "\n" + cleanURL output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + "\n" + cleanURL
} }
}
if i > 0 { if i > 0 {
output = output + "\n\n---\n\n" output = output + "\n\n---\n\n"