feat: pretty shitty code

This commit is contained in:
2024-11-20 20:18:45 -05:00
parent 91741b38a1
commit 3eeb4c8b48
9 changed files with 269 additions and 3 deletions

37
site/templates.go Normal file
View File

@@ -0,0 +1,37 @@
package site
import (
"embed"
_ "embed"
"fmt"
"html/template"
"io/fs"
"path"
"strings"
)
var templates map[string]*template.Template
func init() {
templates = make(map[string]*template.Template)
fs.WalkDir(templateContent, "templates", func(p string, d fs.DirEntry, err error) error {
if d.IsDir() || !strings.HasSuffix(p, ".html") {
return nil
}
basePath := path.Base(p)
templates[basePath] = template.Must(template.ParseFS(templateContent, p, "templates/_layout.html.tmpl"))
fmt.Println(path.Base(p))
return nil
})
fmt.Printf("successfully parsed templates: ")
for k, t := range templates {
fmt.Printf("%s: %s \n", k, t.Name())
}
fmt.Println()
}
//go:embed templates/*
var templateContent embed.FS
//go:embed static/*
var staticContent embed.FS