feat: html static templates
This commit is contained in:
parent
9d0da00371
commit
e9fc659a5a
12 changed files with 91 additions and 100 deletions
29
src/tmpl.go
Normal file
29
src/tmpl.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var TMPL map[string][]byte
|
||||
|
||||
// TODO not use a global
|
||||
// TODO use range instead of if else in header.html
|
||||
func generateTmpl() {
|
||||
files, _ := filepath.Glob("html/*.html")
|
||||
re := regexp.MustCompile("html(/.+).html")
|
||||
|
||||
TMPL = make(map[string][]byte, len(files))
|
||||
for _, f := range files {
|
||||
b := new(bytes.Buffer)
|
||||
name := re.FindStringSubmatch(f)[1]
|
||||
t, _ := template.ParseFiles(f)
|
||||
t.ParseGlob("tmpl/*.tmpl")
|
||||
t.Execute(b, map[string]any{
|
||||
"name": name,
|
||||
})
|
||||
TMPL[name] = b.Bytes()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue