-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.go
More file actions
40 lines (35 loc) · 746 Bytes
/
render.go
File metadata and controls
40 lines (35 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"html/template"
"os"
"path"
"time"
"github.com/bake/goread/feed"
"github.com/pkg/errors"
)
type page struct {
tmpl *template.Template
out string
max int
Category string
Categories []string
Items []*feed.Item
Updated time.Time
Version string
}
func (p *page) render(name, category string, items []*feed.Item) error {
p.Items = items
p.Category = category
p.Updated = time.Now()
w, err := os.Create(path.Join(p.out, name+".html"))
if len(p.Items) > p.max {
p.Items = p.Items[:p.max]
}
if err != nil {
return errors.Wrap(err, "could not generate output file")
}
if err := p.tmpl.Execute(w, p); err != nil {
return errors.Wrap(err, "could not execute template")
}
return nil
}