feat: add formatDate template function and subdirectory glob support

This commit is contained in:
2026-05-15 19:36:12 +02:00
parent ae64f39e2c
commit 897d4a0c2e

View File

@@ -11,6 +11,7 @@ import (
"slices"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/render"
@@ -140,6 +141,16 @@ func ProvideRenderer() (*Renderer, error) {
}
return (current / total) * 100
},
"formatDate": func(dateStr string) string {
t, err := time.Parse(time.RFC3339, dateStr)
if err != nil {
t, err = time.Parse("2006-01-02T15:04:05+00:00", dateStr)
if err != nil {
return dateStr
}
}
return t.Format("Jan 2, 2006")
},
}
pages, err := filepath.Glob(filepath.Join(".", "templates", "*.gohtml"))
@@ -147,6 +158,13 @@ func ProvideRenderer() (*Renderer, error) {
return nil, err
}
subpages, err := filepath.Glob(filepath.Join(".", "templates", "anime", "*.gohtml"))
if err != nil {
return nil, err
}
allPages := append(pages, subpages...)
components, err := filepath.Glob(filepath.Join(".", "templates", "components", "*.gohtml"))
if err != nil {
return nil, err
@@ -154,7 +172,7 @@ func ProvideRenderer() (*Renderer, error) {
basePath := filepath.Join(".", "templates", "base.gohtml")
for _, page := range pages {
for _, page := range allPages {
name := filepath.Base(page)
if name == "base.gohtml" {
continue