parent
9420df0a4c
commit
1f0c0ba4b1
9 changed files with 39 additions and 54 deletions
31
src/tmpl.go
31
src/tmpl.go
|
|
@ -1,31 +0,0 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue