2022-03-19 20:57:33 +00:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
2022-03-20 09:04:08 +00:00
|
|
|
"embed"
|
2022-03-19 20:57:33 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae/categories"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/util"
|
|
|
|
"html/template"
|
2022-03-20 08:21:59 +00:00
|
|
|
"io"
|
2022-03-19 20:57:33 +00:00
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-03-20 09:04:08 +00:00
|
|
|
//go:embed categories.html
|
|
|
|
var fs embed.FS
|
2022-03-20 08:21:59 +00:00
|
|
|
|
|
|
|
var (
|
2022-03-20 09:04:08 +00:00
|
|
|
categoryT *template.Template
|
2022-03-20 08:21:59 +00:00
|
|
|
)
|
2022-03-19 20:57:33 +00:00
|
|
|
|
|
|
|
func init() {
|
2022-03-20 09:04:08 +00:00
|
|
|
categoryT = template.Must(template.
|
|
|
|
New("category").
|
|
|
|
Funcs(
|
|
|
|
template.FuncMap{
|
|
|
|
"beautifulName": util.BeautifulName,
|
|
|
|
}).
|
|
|
|
ParseFS(fs, "*"))
|
2022-03-19 20:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func categoryCardHTML(hyphaName string) string {
|
|
|
|
var buf strings.Builder
|
2022-03-20 09:04:08 +00:00
|
|
|
err := categoryT.ExecuteTemplate(&buf, "category card", struct {
|
2022-03-19 20:57:33 +00:00
|
|
|
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
|
|
|
|
2022-03-20 09:04:08 +00:00
|
|
|
func CategoryPageHTML(meta Meta, catName string) {
|
2022-03-20 08:21:59 +00:00
|
|
|
var buf strings.Builder
|
2022-03-20 09:04:08 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-03-20 09:04:08 +00:00
|
|
|
_, err = io.WriteString(meta.W, BaseHTML(
|
2022-03-20 08:21:59 +00:00
|
|
|
"Category "+util.BeautifulName(catName),
|
|
|
|
buf.String(),
|
2022-03-20 09:04:08 +00:00
|
|
|
meta.Lc,
|
|
|
|
meta.U,
|
2022-03-20 08:21:59 +00:00
|
|
|
))
|
2022-03-20 09:04:08 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2022-03-20 08:21:59 +00:00
|
|
|
}
|
2022-03-20 18:24:54 +00:00
|
|
|
|
|
|
|
func CategoryListHTML(meta Meta) {
|
|
|
|
var buf strings.Builder
|
|
|
|
err := categoryT.ExecuteTemplate(&buf, "category list", struct {
|
|
|
|
Categories []string
|
|
|
|
}{
|
|
|
|
categories.List(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
_, err = io.WriteString(meta.W, BaseHTML(
|
|
|
|
"Category list",
|
|
|
|
buf.String(),
|
|
|
|
meta.Lc,
|
|
|
|
meta.U,
|
|
|
|
))
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}
|