package handlers
import (
"embed"
"html/template"
"io/fs"
"log"
"net/http"
"regexp"
)
//go:embed templates/*
var templateFS embed.FS
//go:embed static/*
var staticFS embed.FS
var tagRe = regexp.MustCompile(`<[^>]*>`)
func stripHTML(s string) string {
return tagRe.ReplaceAllString(s, "")
}
func ParseTemplates() (*template.Template, error) {
funcMap := template.FuncMap{
"plain": stripHTML,
}
return template.New("").Funcs(funcMap).ParseFS(templateFS, "templates/*.html")
}
func StaticHandler() http.Handler {
sub, err := fs.Sub(staticFS, "static")
if err != nil {
log.Fatal(err)
}
return http.FileServer(http.FS(sub))
}