-
Notifications
You must be signed in to change notification settings - Fork 9
/
template.go
46 lines (36 loc) · 908 Bytes
/
template.go
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
41
42
43
44
45
46
package main
import (
"log"
"text/template"
"github.com/GeertJohan/go.rice"
)
var templates = map[string]*template.Template{}
func loadTemplates() {
templateBox := rice.MustFindBox("templates")
layout, err := templateBox.String("layout.html")
if err != nil {
log.Fatal(err)
}
t := []string{
"index",
"article",
"archive",
}
for _, tplName := range t {
tplContent, err := templateBox.String(tplName + ".html")
if err != nil {
log.Fatal(err)
}
templates[tplName] = template.Must(template.New("layout").Parse(layout + tplContent))
}
feed, err := templateBox.String("feed.atom")
if err != nil {
log.Fatal(err)
}
templates["feed.atom"] = template.Must(template.New("feed.atom").Parse(feed))
sitemap, err := templateBox.String("sitemap.xml")
if err != nil {
log.Fatal(err)
}
templates["sitemap.xml"] = template.Must(template.New("sitemap.xml").Parse(sitemap))
}