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",
"MucNick": "feedbot",
"MaxArticles": 5,
"NoExcerpt": false,
"Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ]
}

View file

@ -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" ]
}

View file

@ -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)

View file

@ -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,6 +194,12 @@ func getArticles(feedURL string, max int) (string, error) {
// Remove redirects and tracking parameters from URL.
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.
description, err := html2text.FromString(article.Description)
if err != nil {
@ -208,6 +214,7 @@ func getArticles(feedURL string, max int) (string, error) {
} else {
output = output + feed.Title + ": *" + article.Title + "*\n\n" + description + "\n" + cleanURL
}
}
if i > 0 {
output = output + "\n\n---\n\n"