/
renderaux.go
123 lines (106 loc) · 3.2 KB
/
renderaux.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"html/template"
"io"
"path/filepath"
"sort"
"strings"
"github.com/Debian/debiman/internal/bundled"
"github.com/Debian/debiman/internal/manpage"
"github.com/Debian/debiman/internal/write"
)
var indexTmpl = mustParseIndexTmpl()
func mustParseIndexTmpl() *template.Template {
return template.Must(template.Must(commonTmpls.Clone()).New("index").Parse(bundled.Asset("index.tmpl")))
}
var faqTmpl = mustParseFaqTmpl()
func mustParseFaqTmpl() *template.Template {
return template.Must(template.Must(commonTmpls.Clone()).New("faq").Parse(bundled.Asset("faq.tmpl")))
}
var aboutTmpl = mustParseAboutTmpl()
func mustParseAboutTmpl() *template.Template {
return template.Must(template.Must(commonTmpls.Clone()).New("about").Parse(bundled.Asset("about.tmpl")))
}
type bySuiteStr []string
func (p bySuiteStr) Len() int { return len(p) }
func (p bySuiteStr) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p bySuiteStr) Less(i, j int) bool {
orderi, oki := sortOrder[p[i]]
orderj, okj := sortOrder[p[j]]
if !oki || !okj {
panic(fmt.Sprintf("either %q or %q is an unknown suite. known: %+v", p[i], p[j], sortOrder))
}
return orderi < orderj
}
func renderAux(destDir string, gv globalView) error {
suites := make([]string, 0, len(gv.suites))
for suite := range gv.suites {
suites = append(suites, suite)
}
sort.Stable(bySuiteStr(suites))
if err := write.Atomically(filepath.Join(destDir, "index.html.gz"), true, func(w io.Writer) error {
return indexTmpl.Execute(w, struct {
Title string
DebimanVersion string
Breadcrumbs breadcrumbs
FooterExtra string
Suites []string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "index",
Suites: suites,
DebimanVersion: debimanVersion,
})
}); err != nil {
return err
}
if err := write.Atomically(filepath.Join(destDir, "faq.html.gz"), true, func(w io.Writer) error {
return faqTmpl.Execute(w, struct {
Title string
DebimanVersion string
Breadcrumbs breadcrumbs
FooterExtra string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "FAQ",
DebimanVersion: debimanVersion,
})
}); err != nil {
return err
}
if err := write.Atomically(filepath.Join(destDir, "about.html.gz"), true, func(w io.Writer) error {
return aboutTmpl.Execute(w, struct {
Title string
DebimanVersion string
Breadcrumbs breadcrumbs
FooterExtra string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: "About",
DebimanVersion: debimanVersion,
})
}); err != nil {
return err
}
for name, content := range bundled.AssetsFiltered(func(fn string) bool {
return !strings.HasSuffix(fn, ".tmpl") && !strings.HasSuffix(fn, "style.css")
}) {
if err := write.Atomically(filepath.Join(destDir, filepath.Base(name)+".gz"), true, func(w io.Writer) error {
_, err := io.WriteString(w, content)
return err
}); err != nil {
return err
}
if err := write.Atomically(filepath.Join(destDir, filepath.Base(name)), false, func(w io.Writer) error {
_, err := io.WriteString(w, content)
return err
}); err != nil {
return err
}
}
return nil
}