50 lines
1 KiB
Go
50 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var ALIASES map[string]string
|
|
func generateAliases() {
|
|
f, err := os.ReadFile("aliases.txt")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
ALIASES = make(map[string]string)
|
|
for l := range strings.SplitSeq(string(f), "\n") {
|
|
sp := strings.Fields(l)
|
|
|
|
if len(sp) == 2 {
|
|
ALIASES[sp[0]] = sp[1]
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|