package html import ( "embed" "html/template" "io" "time" "github.com/Jaculabilis/intake/core" ) func rawHtml(str string) template.HTML { return template.HTML(str) } func tsToDate(t int) string { tm := time.Unix(int64(t), 0).UTC() return tm.Format(time.DateTime) } var funcs = template.FuncMap{ "raw": rawHtml, "tsToDate": tsToDate, } //go:embed intake.css var Stylesheet []byte //go:embed htmx.org@2.0.4.js var Htmx []byte //go:embed *.html var templates embed.FS func load(files ...string) *template.Template { files = append([]string{"layout.html"}, files...) return template.Must(template.New("layout.html").Funcs(funcs).ParseFS(templates, files...)) } var home = load("home.html") type SourceData struct { Name string } type HomeData struct { Sources []SourceData } func Home(writer io.Writer, data HomeData) error { return home.Execute(writer, data) } var feed = load("feed.html", "item.html") type FeedData struct { Items []core.Item } func Feed(writer io.Writer, data FeedData) error { return feed.Execute(writer, data) } var item = load("itemPage.html", "item.html") type ItemData struct { Item core.Item Open bool } func Item(writer io.Writer, data ItemData) error { return item.Execute(writer, data) }