mirror of
https://salsa.debian.org/mdosch/feed-to-muc.git
synced 2024-11-22 14:08:39 +01:00
Added config option to post only the article link without excerpt.
This commit is contained in:
parent
5a5014d449
commit
7e2c58256d
4 changed files with 24 additions and 14 deletions
|
@ -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" ]
|
||||
}
|
||||
|
|
|
@ -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" ]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue