feat: pretty shitty code
This commit is contained in:
37
site/templates.go
Normal file
37
site/templates.go
Normal 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
|
||||
Reference in New Issue
Block a user