Files
tamabox/dev/checktpl/main.go
T
tamakyi e3e59e7c69 chore: baseline snapshot before moderation-strictness feature
Repo .git was damaged (refs/ missing, index truncated, object store near-empty).
Repaired via git init (rebuilt refs), stale index preserved as .git/index.corrupt-20260910.bak,
then full worktree committed as a rollback baseline.
2026-09-10 10:56:27 +08:00

46 lines
1.0 KiB
Go

package main
import (
"fmt"
"io/fs"
"os"
"strings"
texttmpl "text/template"
"github.com/tamakyi/TamaBox/internal/template"
"github.com/tamakyi/TamaBox/templates"
)
// mergedFuncMap 将项目实际使用的模板函数(含 t 等 i18n 函数)合并为 text/template.FuncMap。
// 不使用 FuncMap 直接解析会因 "t" 等函数未定义而误报模板错误。
func mergedFuncMap() texttmpl.FuncMap {
fm := texttmpl.FuncMap{}
for _, m := range template.FuncMap() {
for k, v := range m {
fm[k] = v
}
}
return fm
}
func main() {
hasErr := false
_ = fs.WalkDir(templates.FS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || !strings.HasSuffix(path, ".html") {
return nil
}
if _, err := texttmpl.New(path).Funcs(mergedFuncMap()).ParseFS(templates.FS, path); err != nil {
fmt.Println("TEMPLATE ERROR:", path, "->", err)
hasErr = true
}
return nil
})
if hasErr {
os.Exit(1)
}
fmt.Println("all templates syntax OK")
}