all repos — navani @ master

forlater's primary mail processing service

mail/template.go (view raw)

 1package mail
 2
 3import (
 4	"bytes"
 5	"html/template"
 6	"path/filepath"
 7
 8	"git.icyphox.sh/forlater/navani/reader"
 9)
10
11func RenderTemplate(file string, article *reader.Article) ([]byte, error) {
12	t, err := template.ParseGlob(filepath.Join("templates", "*.tpl"))
13	if err != nil {
14		return nil, err
15	}
16
17	buf := &bytes.Buffer{}
18	if err := t.ExecuteTemplate(buf, file, struct {
19		Content template.HTML
20		Title   string
21		Byline  string
22		URL     string
23	}{
24		template.HTML(article.Content),
25		article.Title,
26		article.Byline,
27		article.URL.String(),
28	}); err != nil {
29		return nil, err
30	}
31	return buf.Bytes(), nil
32}