-
-
Notifications
You must be signed in to change notification settings - Fork 397
/
template.go
71 lines (60 loc) 路 1.21 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//go:generate statik -src=./tmpl
package main
import (
"html/template"
"log"
"net/http"
"github.com/rakyll/statik/fs"
_ "github.com/reviewdog/reviewdog/doghouse/appengine/statik"
)
var tmplFiles http.FileSystem
func mustParseTemplatesFiles(filenames ...string) *template.Template {
t, err := parseTempaltesFiles(filenames...)
if err != nil {
log.Fatal(err)
}
return t
}
func parseTempaltesFiles(filenames ...string) (*template.Template, error) {
var t *template.Template
for _, filename := range filenames {
if t == nil {
t = template.New(filename)
}
text, err := fs.ReadFile(tmplFiles, filename)
if err != nil {
return nil, err
}
t, err = t.Parse(string(text))
if err != nil {
return nil, err
}
}
return t, nil
}
var (
topTmpl *template.Template
ghTopTmpl *template.Template
ghRepoTmpl *template.Template
)
func initTemplates() {
var err error
tmplFiles, err = fs.New()
if err != nil {
log.Fatal(err)
}
topTmpl = mustParseTemplatesFiles(
"/base.html",
"/index.html",
)
ghTopTmpl = mustParseTemplatesFiles(
"/gh/base.html",
"/gh/header.html",
"/gh/top.html",
)
ghRepoTmpl = mustParseTemplatesFiles(
"/gh/base.html",
"/gh/header.html",
"/gh/repo.html",
)
}