aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-09 01:20:34 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2022-01-09 13:18:32 +0100
commit0384d631d2edb8383d0840940be066d96a5badc7 (patch)
tree71cac6f7f309794b4a72e88afa1c3aedcc6bd6b2 /main.go
parent914be83c6066ffb8103707528f8e8279df97bf63 (diff)
downloadfeed2imap-go-0384d631d2edb8383d0840940be066d96a5badc7.tar.gz
feed2imap-go-0384d631d2edb8383d0840940be066d96a5badc7.tar.bz2
feed2imap-go-0384d631d2edb8383d0840940be066d96a5badc7.zip
#66: Support for specifying custom templates
Diffstat (limited to 'main.go')
-rw-r--r--main.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/main.go b/main.go
index d2d0a3c..e4593be 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ import (
"os"
"github.com/Necoro/feed2imap-go/internal/feed/cache"
+ "github.com/Necoro/feed2imap-go/internal/feed/template"
"github.com/Necoro/feed2imap-go/internal/imap"
"github.com/Necoro/feed2imap-go/pkg/config"
"github.com/Necoro/feed2imap-go/pkg/log"
@@ -62,6 +63,18 @@ func processFeed(cf cache.CachedFeed, client *imap.Client, dryRun bool) {
cf.Commit()
}
+func loadTemplate(path string, tpl template.Template) error {
+ if path == "" {
+ return nil
+ }
+
+ log.Printf("Loading custom %s template from %s", tpl.Name(), path)
+ if err := tpl.LoadFile(path); err != nil {
+ return fmt.Errorf("loading %s template from %s: %w", tpl.Name(), path, err)
+ }
+ return nil
+}
+
func run() error {
flag.Parse()
if printVersion {
@@ -107,6 +120,15 @@ func run() error {
return nil
}
+ if !buildCache {
+ if err = loadTemplate(cfg.HtmlTemplate, template.Html); err != nil {
+ return err
+ }
+ if err = loadTemplate(cfg.TextTemplate, template.Text); err != nil {
+ return err
+ }
+ }
+
imapErr := make(chan error, 1)
var c *imap.Client
if !dryRun && !buildCache {