1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/views/categories.go

67 lines
1.1 KiB
Go
Raw Normal View History

package views
import (
"embed"
"github.com/bouncepaw/mycorrhiza/hyphae/categories"
"github.com/bouncepaw/mycorrhiza/util"
"html/template"
2022-03-20 08:21:59 +00:00
"io"
"log"
"strings"
)
//go:embed categories.html
var fs embed.FS
2022-03-20 08:21:59 +00:00
var (
categoryT *template.Template
2022-03-20 08:21:59 +00:00
)
func init() {
categoryT = template.Must(template.
New("category").
Funcs(
template.FuncMap{
"beautifulName": util.BeautifulName,
}).
ParseFS(fs, "*"))
}
func categoryCardHTML(hyphaName string) string {
var buf strings.Builder
err := categoryT.ExecuteTemplate(&buf, "category card", struct {
HyphaName string
Categories []string
}{
hyphaName,
categories.WithHypha(hyphaName),
})
if err != nil {
log.Println(err)
}
return buf.String()
}
2022-03-20 08:21:59 +00:00
func CategoryPageHTML(meta Meta, catName string) {
2022-03-20 08:21:59 +00:00
var buf strings.Builder
err := categoryT.ExecuteTemplate(&buf, "category page", struct {
2022-03-20 08:21:59 +00:00
CatName string
Hyphae []string
}{
catName,
categories.Contents(catName),
})
if err != nil {
log.Println(err)
}
_, err = io.WriteString(meta.W, BaseHTML(
2022-03-20 08:21:59 +00:00
"Category "+util.BeautifulName(catName),
buf.String(),
meta.Lc,
meta.U,
2022-03-20 08:21:59 +00:00
))
if err != nil {
log.Println(err)
}
2022-03-20 08:21:59 +00:00
}