aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-06 22:56:38 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-06 22:56:38 +0200
commite0a857eafebd92d5e94d156997d5d9422a50933f (patch)
tree4430fd19b59f05f82637bb45924009ab36b6c349 /internal
parent9125f573c96001df5e4c76fd2183a9d368a552ab (diff)
downloadfeed2imap-go-e0a857eafebd92d5e94d156997d5d9422a50933f.tar.gz
feed2imap-go-e0a857eafebd92d5e94d156997d5d9422a50933f.tar.bz2
feed2imap-go-e0a857eafebd92d5e94d156997d5d9422a50933f.zip
Improve template
Diffstat (limited to 'internal')
-rw-r--r--internal/feed/item.go16
-rw-r--r--internal/feed/mail.go26
-rw-r--r--internal/feed/template/feed.tpl.go6
3 files changed, 28 insertions, 20 deletions
diff --git a/internal/feed/item.go b/internal/feed/item.go
index b8fb7f7..bbf7668 100644
--- a/internal/feed/item.go
+++ b/internal/feed/item.go
@@ -17,8 +17,8 @@ type feedImage struct {
}
type item struct {
- *gofeed.Feed
*gofeed.Item
+ Feed *gofeed.Feed
feed *Feed
Body string
updateOnly bool
@@ -28,14 +28,22 @@ type item struct {
}
// Creator returns the name of the creating author.
-// MUST NOT have `*item` has the receiver, because the template breaks then.
func (item *item) Creator() string {
- if item.Item.Author != nil {
- return item.Item.Author.Name
+ if item.Author != nil {
+ return item.Author.Name
}
return ""
}
+func (item *item) FeedLink() string {
+ if item.Feed.Link != "" {
+ // the one in the feed itself
+ return item.Feed.FeedLink
+ }
+ // the one in the config
+ return item.feed.Url
+}
+
func (item *item) addReason(reason string) {
if !util.StrContains(item.reasons, reason) {
item.reasons = append(item.reasons, reason)
diff --git a/internal/feed/mail.go b/internal/feed/mail.go
index 0360e10..190e1f2 100644
--- a/internal/feed/mail.go
+++ b/internal/feed/mail.go
@@ -31,10 +31,10 @@ func address(name, address string) []*mail.Address {
func (item *item) fromAddress() []*mail.Address {
switch {
- case item.Item.Author != nil && item.Item.Author.Email != "":
- return address(item.Item.Author.Name, item.Item.Author.Email)
- case item.Item.Author != nil && item.Item.Author.Name != "":
- return address(item.Item.Author.Name, item.defaultEmail())
+ case item.Author != nil && item.Author.Email != "":
+ return address(item.Author.Name, item.Author.Email)
+ case item.Author != nil && item.Author.Name != "":
+ return address(item.Author.Name, item.defaultEmail())
case item.Feed.Author != nil && item.Feed.Author.Email != "":
return address(item.Feed.Author.Name, item.Feed.Author.Email)
case item.Feed.Author != nil && item.Feed.Author.Name != "":
@@ -63,7 +63,7 @@ func (item *item) buildHeader() message.Header {
h.Set("Message-Id", item.messageId())
{ // date
- date := item.Item.PublishedParsed
+ date := item.PublishedParsed
if date == nil {
now := time.Now()
date = &now
@@ -71,12 +71,12 @@ func (item *item) buildHeader() message.Header {
h.SetDate(*date)
}
{ // subject
- subject := item.Item.Title
+ subject := item.Title
if subject == "" {
- subject = item.Item.Published
+ subject = item.Published
}
if subject == "" {
- subject = item.Item.Link
+ subject = item.Link
}
h.SetSubject(subject)
}
@@ -244,7 +244,7 @@ func (item *item) buildBody() {
panic(fmt.Sprintf("URL '%s' of feed '%s' is not a valid URL. How have we ended up here?", feed.Url, feed.Name))
}
- body := getBody(item.Item.Content, item.Item.Description, feed.Body)
+ body := getBody(item.Content, item.Description, feed.Body)
if !feed.InclImages {
item.Body = body
@@ -253,7 +253,7 @@ func (item *item) buildBody() {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
if err != nil {
- log.Errorf("Feed %s: Item %s: Error while parsing html content: %s", feed.Name, item.Item.Link, err)
+ log.Errorf("Feed %s: Item %s: Error while parsing html content: %s", feed.Name, item.Link, err)
if body != "" {
item.Body = "<br />" + body
}
@@ -273,7 +273,7 @@ func (item *item) buildBody() {
srcUrl, err := url.Parse(src)
if err != nil {
log.Errorf("Feed %s: Item %s: Error parsing URL '%s' embedded in item: %s",
- feed.Name, item.Item.Link, src, err)
+ feed.Name, item.Link, src, err)
return
}
imgUrl := feedUrl.ResolveReference(srcUrl)
@@ -281,7 +281,7 @@ func (item *item) buildBody() {
img, mime, err := getImage(imgUrl.String(), feed.Global.Timeout, feed.NoTLS)
if err != nil {
log.Errorf("Feed %s: Item %s: Error fetching image: %s",
- feed.Name, item.Item.Link, err)
+ feed.Name, item.Link, err)
return
}
if img == nil {
@@ -304,7 +304,7 @@ func (item *item) buildBody() {
if err != nil {
item.clearImages()
log.Errorf("Feed %s: Item %s: Error during rendering HTML: %s",
- feed.Name, item.Item.Link, err)
+ feed.Name, item.Link, err)
} else {
body = html
}
diff --git a/internal/feed/template/feed.tpl.go b/internal/feed/template/feed.tpl.go
index 0e09180..2f51bbe 100644
--- a/internal/feed/template/feed.tpl.go
+++ b/internal/feed/template/feed.tpl.go
@@ -64,10 +64,10 @@ const feedTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feedi
{{end}}
<hr width="100%"/>
<table width="100%" cellpadding="0" cellspacing="0">
- {{template "bottomLine" (dict "descr" "Date:" "content" .Item.Published)}}
+ {{template "bottomLine" (dict "descr" "Date:" "content" .Published)}}
{{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}}
- {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Item.Categories))}}
- {{with .Feed.FeedLink}}
+ {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}}
+ {{with .FeedLink}}
{{template "bottomLine" (dict "descr" "Feed-Link:" "content" (print "<a style=\"color: #ababab;\" href=\"" . "\">" . "</a>" | html))}}
{{end}}
</table>`