From 7bfe97f3e72279a17c16803d64a16beb55944332 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Wed, 22 Apr 2020 23:53:31 +0200 Subject: Fix html template --- internal/template/feed.tpl.go | 2 +- internal/template/template.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'internal/template') diff --git a/internal/template/feed.tpl.go b/internal/template/feed.tpl.go index 2bf07f3..3f6470f 100644 --- a/internal/template/feed.tpl.go +++ b/internal/template/feed.tpl.go @@ -70,7 +70,7 @@ const feedTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feedi
{{template "bottomLine" (dict "descr" "Date:" "content" .Item.Published)}} - {{template "bottomLine" (dict "descr" "Author:" "content" .Item.Author.Name)}} + {{with .Item.Author}}{{template "bottomLine" (dict "descr" "Author:" "content" .Name)}}{{end}} {{template "bottomLine" (dict "descr" "Subject:" "content" .Item.Title)}} {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Item.Categories))}}
` diff --git a/internal/template/template.go b/internal/template/template.go index a239484..dd31f51 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -3,7 +3,10 @@ package template import ( "fmt" "html/template" + "strconv" "strings" + + "github.com/Necoro/feed2imap-go/internal/log" ) func dict(v ...string) map[string]string { @@ -29,12 +32,17 @@ func lastUrlPart(url string) string { return split[len(split)-1] } -func byteCount(b int64) string { +func byteCount(str string) string { + b, err := strconv.ParseUint(str, 10, 64) + if err != nil { + log.Printf("Cannot convert '%s' to byte count: %s", str, err) + } + const unit = 1024 if b < unit { return fmt.Sprintf("%d B", b) } - div, exp := int64(unit), 0 + div, exp := uint64(unit), 0 for n := b / unit; n >= unit; n /= unit { div *= unit exp++ -- cgit v1.2.3-54-g00ecf