diff --git a/internal/cmd/reload/reload.go b/internal/cmd/reload/reload.go
index 589013e..8e8721a 100644
--- a/internal/cmd/reload/reload.go
+++ b/internal/cmd/reload/reload.go
@@ -10,11 +10,16 @@ var calls []func()
var str = safety.NewMap[string, string]()
-func GetStr(name string) (string, bool) {
- return str.Load(name)
-}
-func SetStr(name, val string) {
- str.Store(name, val)
+var anyMap = safety.NewMap[string, any]()
+
+func GetAnyValBy[T any](k string, fn func() T) T {
+ v, ok := anyMap.Load(k)
+ if ok {
+ return v.(T)
+ }
+ vv := fn()
+ anyMap.Store(k, vv)
+ return vv
}
func GetStrBy[T any](key, delimiter string, t T, fn ...func(T) string) string {
@@ -52,5 +57,6 @@ func Reload() {
for _, call := range calls {
call()
}
+ anyMap.Flush()
str.Flush()
}
diff --git a/internal/pkg/cache/posts.go b/internal/pkg/cache/posts.go
index 52f2bef..1709070 100644
--- a/internal/pkg/cache/posts.go
+++ b/internal/pkg/cache/posts.go
@@ -3,9 +3,12 @@ package cache
import (
"context"
"fmt"
+ "github.com/fthvgb1/wp-go/helper/number"
"github.com/fthvgb1/wp-go/helper/slice"
+ str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models"
+ "github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/gin-gonic/gin"
"time"
)
@@ -44,9 +47,8 @@ func GetMaxPostId(ctx *gin.Context) (uint64, error) {
func RecentPosts(ctx context.Context, n int) (r []models.Posts) {
nn := n
- if nn <= 5 {
- nn = 10
- }
+ feedNum := str.ToInteger(wpconfig.GetOption("posts_per_rss"), 10)
+ nn = number.Max(n, feedNum)
r, err := recentPostsCaches.GetCache(ctx, time.Second, ctx, nn)
if n < len(r) {
r = r[:n]
diff --git a/internal/pkg/dao/posts.go b/internal/pkg/dao/posts.go
index 64007d1..fc4ba23 100644
--- a/internal/pkg/dao/posts.go
+++ b/internal/pkg/dao/posts.go
@@ -129,8 +129,8 @@ func RecentPosts(a ...any) (r []models.Posts, err error) {
{"post_type", "post"},
{"post_status", "publish"},
}),
- model.Fields("ID,post_title,post_password"),
- model.Order(model.SqlBuilder{{"post_date", "desc"}}),
+ model.Fields("ID,post_title,post_password,post_date_gmt"),
+ model.Order([][]string{{"post_date", "desc"}}),
model.Limit(num),
))
return
diff --git a/internal/theme/fs.go b/internal/theme/fs.go
index 5eaa264..bae4ddb 100644
--- a/internal/theme/fs.go
+++ b/internal/theme/fs.go
@@ -33,7 +33,7 @@ func commonTemplate(t *multipTemplate.MultipleFsTemplate) {
for _, main := range m {
file := filepath.Base(main)
dir := strings.Split(main, "/")[0]
- templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "wp/template.gohtml"))
+ templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "wp/template.gohtml", "wp/*/*/*.gohtml"))
t.SetTemplate(main, templ)
}
}
diff --git a/internal/theme/templateFuncs.go b/internal/theme/templateFuncs.go
index cc31132..ab788d0 100644
--- a/internal/theme/templateFuncs.go
+++ b/internal/theme/templateFuncs.go
@@ -13,6 +13,9 @@ var comFn = template.FuncMap{
"dateCh": func(t time.Time) any {
return t.Format("2006年 01月 02日")
},
+ "timeFormat": func(t time.Time, format string) any {
+ return t.Format(format)
+ },
"getOption": func(k string) string {
return wpconfig.GetOption(k)
},
diff --git a/internal/theme/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml
index dba5de8..367b315 100644
--- a/internal/theme/twentyfifteen/layout/sidebar.gohtml
+++ b/internal/theme/twentyfifteen/layout/sidebar.gohtml
@@ -9,19 +9,7 @@
-
+ {{template "common/recent-posts" .}}