From 0179262628cadd3ed402880a03f3d812f327feec Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 21 Apr 2020 22:20:42 +0200 Subject: Improved HTML creation --- internal/config/config.go | 9 +++++++++ internal/feed/mail.go | 1 + internal/template/feed.tpl.go | 6 +++++- internal/template/template.go | 9 +++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 409cbdf..6c74c2e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,7 @@ import ( "os" "os/user" "runtime" + "runtime/debug" "strings" ) @@ -62,6 +63,14 @@ func (c *Config) WithPartHtml() bool { return false } +func Version() string { + bi, ok := debug.ReadBuildInfo() + if !ok { + return "(unknown)" + } + return bi.Main.Version +} + func hostname() (hostname string) { hostname, err := os.Hostname() if err != nil { diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 94f2ea1..ab468cc 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -39,6 +39,7 @@ func writeToBuffer(b *bytes.Buffer, feed *Feed, item feeditem, cfg config.Config var h mail.Header h.SetAddressList("From", fromAdress(feed, item, cfg)) h.SetAddressList("To", address(feed.Name, cfg.DefaultEmail)) + h.Add("X-Feed2Imap-Version", config.Version()) { // date date := item.Item.PublishedParsed diff --git a/internal/template/feed.tpl.go b/internal/template/feed.tpl.go index f6862d5..2bf07f3 100644 --- a/internal/template/feed.tpl.go +++ b/internal/template/feed.tpl.go @@ -40,9 +40,13 @@ const feedTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feedi +{{with .Item.Description}} +
+ {{html .}} +{{end}} {{with .Item.Content}}
- {{.}} + {{html .}} {{end}} {{with .Item.Enclosures}} diff --git a/internal/template/template.go b/internal/template/template.go index 350a0ed..a239484 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -24,7 +24,7 @@ func join(sep string, parts []string) string { return strings.Join(parts, sep) } -func LastUrlPart(url string) string { +func lastUrlPart(url string) string { split := strings.Split(url, "/") return split[len(split)-1] } @@ -42,11 +42,16 @@ func byteCount(b int64) string { return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "KMGTPE"[exp]) } +func html(s string) template.HTML { + return template.HTML(s) +} + var funcMap = template.FuncMap{ "dict": dict, "join": join, - "lastUrlPart": LastUrlPart, + "lastUrlPart": lastUrlPart, "byteCount": byteCount, + "html": html, } func fromString(name, templateStr string) *template.Template { -- cgit v1.2.3-54-g00ecf