/
rendercontents.go
55 lines (48 loc) · 1.32 KB
/
rendercontents.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
package main
import (
"fmt"
"html/template"
"io"
"os"
"path/filepath"
"sort"
"github.com/Debian/debiman/internal/bundled"
"github.com/Debian/debiman/internal/manpage"
"github.com/Debian/debiman/internal/write"
)
var contentsTmpl = mustParseContentsTmpl()
func mustParseContentsTmpl() *template.Template {
return template.Must(template.Must(commonTmpls.Clone()).New("contents").Parse(bundled.Asset("contents.tmpl")))
}
func renderContents(dest, suite string, bins []string) error {
sort.Strings(bins)
if err := write.Atomically(dest, true, func(w io.Writer) error {
return contentsTmpl.Execute(w, struct {
Title string
DebimanVersion string
Breadcrumbs breadcrumbs
FooterExtra string
Bins []string
Suite string
Meta *manpage.Meta
HrefLangs []*manpage.Meta
}{
Title: fmt.Sprintf("Contents of Debian %s", suite),
DebimanVersion: debimanVersion,
Breadcrumbs: breadcrumbs{
{fmt.Sprintf("/contents-%s.html", suite), suite},
{"", "Contents"},
},
Bins: bins,
Suite: suite,
})
}); err != nil {
return err
}
destPath := filepath.Join(*servingDir, suite, "index.html.gz")
link := fmt.Sprintf("../contents-%s.html.gz", suite)
if err := os.Symlink(link, destPath); err != nil && !os.IsExist(err) {
return err
}
return nil
}