Co-authored-by: stcb <21@stcb.cc> Reviewed-on: icing/G-EIP-700-TLS-7-1-eip-stephane.corbiere#4 Co-authored-by: ange <ange@yw5n.com> Co-committed-by: ange <ange@yw5n.com>
32 lines
688 B
Go
32 lines
688 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"path/filepath"
|
|
"regexp"
|
|
)
|
|
|
|
var TMPL map[string][]byte
|
|
|
|
func generateTmpl() {
|
|
files, _ := filepath.Glob("html/*.html")
|
|
re := regexp.MustCompile("html/(.+).html")
|
|
pages := make([]string, len(files))
|
|
|
|
for i, f := range files {
|
|
pages[i] = re.FindStringSubmatch(f)[1]
|
|
}
|
|
TMPL = make(map[string][]byte, len(files))
|
|
for i, f := range files {
|
|
b := new(bytes.Buffer)
|
|
t, _ := template.ParseFiles(f)
|
|
t.ParseGlob("tmpl/*.tmpl")
|
|
t.Execute(b, map[string]any{
|
|
"page": pages[i],
|
|
"pages": pages,
|
|
})
|
|
TMPL[pages[i]] = b.Bytes()
|
|
}
|
|
}
|