|
@@ -4,6 +4,7 @@ import (
|
|
|
"bytes"
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "net/url"
|
|
|
"os"
|
|
|
"os/exec"
|
|
|
"os/signal"
|
|
@@ -58,22 +59,36 @@ type CommandPublisher struct {
|
|
|
func (p CommandPublisher) Publish(event rss.Event, formatter func(rss.Event) string) error {
|
|
|
log.Printf("[INFO] lancio - %s ", strings.Join(p.Command, " "))
|
|
|
cmd := exec.Command(p.Command[0], p.Command[1:]...)
|
|
|
+ enclosuresUrls := []string{}
|
|
|
+ for _, enclosure := range event.Item.Enclosures {
|
|
|
+ enclosuresUrls = append(enclosuresUrls, url.QueryEscape(enclosure.URL))
|
|
|
+ }
|
|
|
cmd.Env = []string{"RSS=1",
|
|
|
fmt.Sprintf("RSS_TITLE=%s", event.Title),
|
|
|
fmt.Sprintf("RSS_GUID=%s", event.GUID),
|
|
|
fmt.Sprintf("RSS_LINK=%s", event.Link),
|
|
|
- fmt.Sprintf("RSS_AUTHOR=%s", event.Item.Author),
|
|
|
- fmt.Sprintf("RSS_IMAGE=%s", event.Item.Image),
|
|
|
fmt.Sprintf("RSS_PUBDATE=%s", event.Item.Published),
|
|
|
fmt.Sprintf("RSS_CATEGORIES=%s", strings.Join(event.Item.Categories, ";")),
|
|
|
fmt.Sprintf("RSS_DESCRIPTION=%s", event.Item.Description),
|
|
|
- fmt.Sprintf("RSS_BODY=%s", event.Item.Content),
|
|
|
+ fmt.Sprintf("RSS_ENCLOSURES=%s", strings.Join(enclosuresUrls, ";")),
|
|
|
// metadata that apply to the whole feed
|
|
|
fmt.Sprintf("RSS_CHAN_TITLE=%s", event.Feed.Title),
|
|
|
fmt.Sprintf("RSS_CHAN_LINK=%s", event.Feed.Link),
|
|
|
- fmt.Sprintf("RSS_CHAN_AUTHOR=%s", event.Feed.Author),
|
|
|
fmt.Sprintf("RSS_CHAN_LANGUAGE=%s", event.Feed.Language),
|
|
|
}
|
|
|
+ if event.Item.Author != nil {
|
|
|
+ cmd.Env = append(cmd.Env,
|
|
|
+ fmt.Sprintf("RSS_AUTHOR=%s", event.Item.Author.Name),
|
|
|
+ fmt.Sprintf("RSS_AUTHOR_EMAIL=%s", event.Item.Author.Email),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if event.Feed.Author != nil {
|
|
|
+ cmd.Env = append(cmd.Env,
|
|
|
+ fmt.Sprintf("RSS_CHAN_AUTHOR=%s", event.Feed.Author.Name))
|
|
|
+ }
|
|
|
+ if event.Item.Image != nil {
|
|
|
+ cmd.Env = append(cmd.Env, fmt.Sprintf("RSS_IMAGE=%s", event.Item.Image.URL))
|
|
|
+ }
|
|
|
textbuf := bytes.NewBuffer([]byte(event.Item.Content))
|
|
|
cmd.Stdin = textbuf
|
|
|
cmd.Stdout = os.Stderr
|