feat: add formatDate template function and subdirectory glob support
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/render"
|
"github.com/gin-gonic/gin/render"
|
||||||
@@ -140,6 +141,16 @@ func ProvideRenderer() (*Renderer, error) {
|
|||||||
}
|
}
|
||||||
return (current / total) * 100
|
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"))
|
pages, err := filepath.Glob(filepath.Join(".", "templates", "*.gohtml"))
|
||||||
@@ -147,6 +158,13 @@ func ProvideRenderer() (*Renderer, error) {
|
|||||||
return nil, err
|
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"))
|
components, err := filepath.Glob(filepath.Join(".", "templates", "components", "*.gohtml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -154,7 +172,7 @@ func ProvideRenderer() (*Renderer, error) {
|
|||||||
|
|
||||||
basePath := filepath.Join(".", "templates", "base.gohtml")
|
basePath := filepath.Join(".", "templates", "base.gohtml")
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range allPages {
|
||||||
name := filepath.Base(page)
|
name := filepath.Base(page)
|
||||||
if name == "base.gohtml" {
|
if name == "base.gohtml" {
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user