文件目录调整及小优化

This commit is contained in:
xing 2023-01-14 12:21:31 +08:00
parent 57f32f1cfc
commit 66c8ba9de9
21 changed files with 121 additions and 80 deletions

View File

@ -7,8 +7,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
cache2 "github/fthvgb1/wp-go/internal/cache"
"github/fthvgb1/wp-go/internal/mail" "github/fthvgb1/wp-go/internal/mail"
cache2 "github/fthvgb1/wp-go/internal/pkg/cache"
"github/fthvgb1/wp-go/internal/pkg/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/pkg/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"

View File

@ -5,10 +5,11 @@ import (
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/cache" cache2 "github/fthvgb1/wp-go/internal/pkg/cache"
"github/fthvgb1/wp-go/internal/pkg/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/pkg/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
"github/fthvgb1/wp-go/internal/templates"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"math/rand" "math/rand"
"net/http" "net/http"
@ -28,10 +29,10 @@ func Detail(c *gin.Context) {
hh := detailHandler{ hh := detailHandler{
c, c,
} }
recent := cache.RecentPosts(c, 5) recent := cache2.RecentPosts(c, 5)
archive := cache.Archives(c) archive := cache2.Archives(c)
categoryItems := cache.Categories(c) categoryItems := cache2.Categories(c)
recentComments := cache.RecentComments(c, 5) recentComments := cache2.RecentComments(c, 5)
var h = gin.H{ var h = gin.H{
"title": wpconfig.Options.Value("blogname"), "title": wpconfig.Options.Value("blogname"),
"options": wpconfig.Options, "options": wpconfig.Options,
@ -51,7 +52,11 @@ func Detail(c *gin.Context) {
if isApproveComment == true { if isApproveComment == true {
return return
} }
c.HTML(status, helper.StrJoin(wpconfig.Options.Value("template"), "/posts/detail.gohtml"), h) tmlp := wpconfig.Options.Value("template")
if i, err := templates.IsTemplateIsExist(tmlp); err != nil || !i {
tmlp = "twentyfifteen"
}
c.HTML(status, helper.StrJoin(tmlp, "/posts/detail.gohtml"), h)
}() }()
id := c.Param("id") id := c.Param("id")
Id := 0 Id := 0
@ -62,12 +67,12 @@ func Detail(c *gin.Context) {
} }
} }
ID := uint64(Id) ID := uint64(Id)
maxId, err := cache.GetMaxPostId(c) maxId, err := cache2.GetMaxPostId(c)
logs.ErrPrintln(err, "get max post id") logs.ErrPrintln(err, "get max post id")
if ID > maxId || err != nil { if ID > maxId || err != nil {
return return
} }
post, err := cache.GetPostById(c, ID) post, err := cache2.GetPostById(c, ID)
if post.Id == 0 || err != nil { if post.Id == 0 || err != nil {
return return
} }
@ -76,7 +81,7 @@ func Detail(c *gin.Context) {
if post.CommentCount > 0 || post.CommentStatus == "open" { if post.CommentCount > 0 || post.CommentStatus == "open" {
showComment = true showComment = true
} }
user := cache.GetUserById(c, post.PostAuthor) user := cache2.GetUserById(c, post.PostAuthor)
plugins.PasswordProjectTitle(&post) plugins.PasswordProjectTitle(&post)
if post.PostPassword != "" && pw != post.PostPassword { if post.PostPassword != "" && pw != post.PostPassword {
plugins.PasswdProjectContent(&post) plugins.PasswdProjectContent(&post)
@ -89,10 +94,10 @@ func Detail(c *gin.Context) {
return return
} }
plugins.ApplyPlugin(plugins.NewPostPlugin(c, plugins.Detail), &post) plugins.ApplyPlugin(plugins.NewPostPlugin(c, plugins.Detail), &post)
comments, err := cache.PostComments(c, post.Id) comments, err := cache2.PostComments(c, post.Id)
logs.ErrPrintln(err, "get post comment", post.Id) logs.ErrPrintln(err, "get post comment", post.Id)
commentss := treeComments(comments) commentss := treeComments(comments)
prev, next, err := cache.GetContextPost(c, post.Id, post.PostDate) prev, next, err := cache2.GetContextPost(c, post.Id, post.PostDate)
logs.ErrPrintln(err, "get pre and next post", post.Id, post.PostDate) logs.ErrPrintln(err, "get pre and next post", post.Id, post.PostDate)
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.Options.Value("blogname")) h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.Options.Value("blogname"))
h["post"] = post h["post"] = post

View File

@ -5,7 +5,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
cache2 "github/fthvgb1/wp-go/internal/cache" cache3 "github/fthvgb1/wp-go/internal/pkg/cache"
"github/fthvgb1/wp-go/internal/pkg/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
models2 "github/fthvgb1/wp-go/internal/pkg/models" models2 "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
@ -78,11 +78,11 @@ func Feed(c *gin.Context) {
func feed(arg ...any) (xml []string, err error) { func feed(arg ...any) (xml []string, err error) {
c := arg[0].(*gin.Context) c := arg[0].(*gin.Context)
r := cache2.RecentPosts(c, 10) r := cache3.RecentPosts(c, 10)
ids := helper.SliceMap(r, func(t models2.Posts) uint64 { ids := helper.SliceMap(r, func(t models2.Posts) uint64 {
return t.Id return t.Id
}) })
posts, err := cache2.GetPostsByIds(c, ids) posts, err := cache3.GetPostsByIds(c, ids)
if err != nil { if err != nil {
return return
} }
@ -102,7 +102,7 @@ func feed(arg ...any) (xml []string, err error) {
} else if t.CommentStatus == "open" && t.CommentCount == 0 { } else if t.CommentStatus == "open" && t.CommentCount == 0 {
l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id) l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id)
} }
user := cache2.GetUserById(c, t.PostAuthor) user := cache3.GetUserById(c, t.PostAuthor)
return rss2.Item{ return rss2.Item{
Title: t.PostTitle, Title: t.PostTitle,
@ -158,17 +158,17 @@ func postFeed(arg ...any) (x string, err error) {
} }
} }
ID := uint64(Id) ID := uint64(Id)
maxId, err := cache2.GetMaxPostId(c) maxId, err := cache3.GetMaxPostId(c)
logs.ErrPrintln(err, "get max post id") logs.ErrPrintln(err, "get max post id")
if ID > maxId || err != nil { if ID > maxId || err != nil {
return return
} }
post, err := cache2.GetPostById(c, ID) post, err := cache3.GetPostById(c, ID)
if post.Id == 0 || err != nil { if post.Id == 0 || err != nil {
return return
} }
plugins.PasswordProjectTitle(&post) plugins.PasswordProjectTitle(&post)
comments, err := cache2.PostComments(c, post.Id) comments, err := cache3.PostComments(c, post.Id)
if err != nil { if err != nil {
return return
} }
@ -228,19 +228,19 @@ func CommentsFeed(c *gin.Context) {
func commentsFeed(args ...any) (r []string, err error) { func commentsFeed(args ...any) (r []string, err error) {
c := args[0].(*gin.Context) c := args[0].(*gin.Context)
commens := cache2.RecentComments(c, 10) commens := cache3.RecentComments(c, 10)
rs := templateRss rs := templateRss
rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname")) rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname"))
rs.LastBuildDate = time.Now().Format(timeFormat) rs.LastBuildDate = time.Now().Format(timeFormat)
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl")) rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl"))
com, err := cache2.GetCommentByIds(c, helper.SliceMap(commens, func(t models2.Comments) uint64 { com, err := cache3.GetCommentByIds(c, helper.SliceMap(commens, func(t models2.Comments) uint64 {
return t.CommentId return t.CommentId
})) }))
if nil != err { if nil != err {
return []string{}, err return []string{}, err
} }
rs.Items = helper.SliceMap(com, func(t models2.Comments) rss2.Item { rs.Items = helper.SliceMap(com, func(t models2.Comments) rss2.Item {
post, _ := cache2.GetPostById(c, t.CommentPostId) post, _ := cache3.GetPostById(c, t.CommentPostId)
plugins.PasswordProjectTitle(&post) plugins.PasswordProjectTitle(&post)
desc := "评论受保护:要查看请输入密码。" desc := "评论受保护:要查看请输入密码。"
content := t.CommentContent content := t.CommentContent

View File

@ -5,10 +5,11 @@ import (
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/cache" cache2 "github/fthvgb1/wp-go/internal/pkg/cache"
dao "github/fthvgb1/wp-go/internal/dao" dao "github/fthvgb1/wp-go/internal/pkg/dao"
"github/fthvgb1/wp-go/internal/pkg/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
"github/fthvgb1/wp-go/internal/templates"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"math" "math"
@ -114,7 +115,7 @@ func (h *indexHandle) parseParams() (err error) {
h.category = category h.category = category
username := h.c.Param("author") username := h.c.Param("author")
if username != "" { if username != "" {
user, er := cache.GetUserByName(h.c, username) user, er := cache2.GetUserByName(h.c, username)
if er != nil { if er != nil {
err = er err = er
return return
@ -181,10 +182,10 @@ func Index(c *gin.Context) {
var postIds []models.Posts var postIds []models.Posts
var totalRaw int var totalRaw int
var err error var err error
archive := cache.Archives(c) archive := cache2.Archives(c)
recent := cache.RecentPosts(c, 5) recent := cache2.RecentPosts(c, 5)
categoryItems := cache.Categories(c) categoryItems := cache2.Categories(c)
recentComments := cache.RecentComments(c, 5) recentComments := cache2.RecentComments(c, 5)
ginH := gin.H{ ginH := gin.H{
"options": wpconfig.Options, "options": wpconfig.Options,
"recentPosts": recent, "recentPosts": recent,
@ -201,7 +202,11 @@ func Index(c *gin.Context) {
stat = http.StatusInternalServerError stat = http.StatusInternalServerError
return return
} }
c.HTML(stat, helper.StrJoin(wpconfig.Options.Value("template"), "/posts/index.gohtml"), ginH) tmlp := wpconfig.Options.Value("template")
if i, err := templates.IsTemplateIsExist(tmlp); err != nil || !i {
tmlp = "twentyfifteen"
}
c.HTML(stat, helper.StrJoin(tmlp, "/posts/index.gohtml"), ginH)
}() }()
err = h.parseParams() err = h.parseParams()
if err != nil { if err != nil {
@ -209,14 +214,14 @@ func Index(c *gin.Context) {
} }
ginH["title"] = h.getTitle() ginH["title"] = h.getTitle()
if c.Param("month") != "" { if c.Param("month") != "" {
postIds, totalRaw, err = cache.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order) postIds, totalRaw, err = cache2.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
if err != nil { if err != nil {
return return
} }
} else if h.search != "" { } else if h.search != "" {
postIds, totalRaw, err = cache.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status) postIds, totalRaw, err = cache2.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
} else { } else {
postIds, totalRaw, err = cache.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status) postIds, totalRaw, err = cache2.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
} }
if err != nil { if err != nil {
return return

View File

@ -4,13 +4,13 @@ import (
"flag" "flag"
"fmt" "fmt"
"github/fthvgb1/wp-go/internal/actions" "github/fthvgb1/wp-go/internal/actions"
"github/fthvgb1/wp-go/internal/cache" "github/fthvgb1/wp-go/internal/cmd/route"
"github/fthvgb1/wp-go/internal/mail" "github/fthvgb1/wp-go/internal/mail"
"github/fthvgb1/wp-go/internal/pkg/cache"
"github/fthvgb1/wp-go/internal/pkg/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/pkg/db" "github/fthvgb1/wp-go/internal/pkg/db"
"github/fthvgb1/wp-go/internal/pkg/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
"github/fthvgb1/wp-go/internal/route"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"log" "log"

View File

@ -6,8 +6,8 @@ import (
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie" "github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
actions2 "github/fthvgb1/wp-go/internal/actions" "github/fthvgb1/wp-go/internal/actions"
middleware2 "github/fthvgb1/wp-go/internal/middleware" "github/fthvgb1/wp-go/internal/middleware"
"github/fthvgb1/wp-go/internal/pkg/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/static" "github/fthvgb1/wp-go/internal/static"
"github/fthvgb1/wp-go/internal/templates" "github/fthvgb1/wp-go/internal/templates"
@ -40,14 +40,14 @@ func SetupRouter() (*gin.Engine, func()) {
return wpconfig.Options.Value(k) return wpconfig.Options.Value(k)
}, },
}).SetTemplate() }).SetTemplate()
validServerName, reloadValidServerNameFn := middleware2.ValidateServerNames() validServerName, reloadValidServerNameFn := middleware.ValidateServerNames()
fl, flReload := middleware2.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime) fl, flReload := middleware.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime)
r.Use( r.Use(
gin.Logger(), gin.Logger(),
validServerName, validServerName,
middleware2.RecoverAndSendMail(gin.DefaultErrorWriter), middleware.RecoverAndSendMail(gin.DefaultErrorWriter),
fl, fl,
middleware2.SetStaticFileCache, middleware.SetStaticFileCache,
) )
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用 //gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
if c.Gzip { if c.Gzip {
@ -65,24 +65,24 @@ func SetupRouter() (*gin.Engine, func()) {
})) }))
store := cookie.NewStore([]byte("secret")) store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("go-wp", store)) r.Use(sessions.Sessions("go-wp", store))
sl, slRload := middleware2.SearchLimit(c.SingleIpSearchNum) sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum)
r.GET("/", sl, actions2.Index) r.GET("/", sl, actions.Index)
r.GET("/page/:page", actions2.Index) r.GET("/page/:page", actions.Index)
r.GET("/p/category/:category", actions2.Index) r.GET("/p/category/:category", actions.Index)
r.GET("/p/category/:category/page/:page", actions2.Index) r.GET("/p/category/:category/page/:page", actions.Index)
r.GET("/p/tag/:tag", actions2.Index) r.GET("/p/tag/:tag", actions.Index)
r.GET("/p/tag/:tag/page/:page", actions2.Index) r.GET("/p/tag/:tag/page/:page", actions.Index)
r.GET("/p/date/:year/:month", actions2.Index) r.GET("/p/date/:year/:month", actions.Index)
r.GET("/p/date/:year/:month/page/:page", actions2.Index) r.GET("/p/date/:year/:month/page/:page", actions.Index)
r.GET("/p/author/:author", actions2.Index) r.GET("/p/author/:author", actions.Index)
r.GET("/p/author/:author/page/:page", actions2.Index) r.GET("/p/author/:author/page/:page", actions.Index)
r.POST("/login", actions2.Login) r.POST("/login", actions.Login)
r.GET("/p/:id", actions2.Detail) r.GET("/p/:id", actions.Detail)
r.GET("/p/:id/feed", actions2.PostFeed) r.GET("/p/:id/feed", actions.PostFeed)
r.GET("/feed", actions2.Feed) r.GET("/feed", actions.Feed)
r.GET("/comments/feed", actions2.CommentsFeed) r.GET("/comments/feed", actions.CommentsFeed)
cfl, _ := middleware2.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime) cfl, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime)
r.POST("/comment", cfl, actions2.PostComment) r.POST("/comment", cfl, actions.PostComment)
if gin.Mode() != gin.ReleaseMode { if gin.Mode() != gin.ReleaseMode {
pprof.Register(r, "dev/pprof") pprof.Register(r, "dev/pprof")
} }

View File

@ -3,15 +3,15 @@ package cache
import ( import (
"context" "context"
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
dao "github/fthvgb1/wp-go/internal/dao"
"github/fthvgb1/wp-go/internal/pkg/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/pkg/dao"
"github/fthvgb1/wp-go/internal/pkg/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
models2 "github/fthvgb1/wp-go/internal/pkg/models" models2 "github/fthvgb1/wp-go/internal/pkg/models"
"sync" "sync"
"time" "time"
) )
var postContextCache *cache.MapCache[uint64, dao.PostContext] var postContextCache *cache.MapCache[uint64, common.PostContext]
var archivesCaches *Arch var archivesCaches *Arch
var categoryCaches *cache.SliceCache[models2.TermsMy] var categoryCaches *cache.SliceCache[models2.TermsMy]
var recentPostsCaches *cache.SliceCache[models2.Posts] var recentPostsCaches *cache.SliceCache[models2.Posts]
@ -22,8 +22,8 @@ var postsCache *cache.MapCache[uint64, models2.Posts]
var postMetaCache *cache.MapCache[uint64, map[string]any] var postMetaCache *cache.MapCache[uint64, map[string]any]
var monthPostsCache *cache.MapCache[string, []uint64] var monthPostsCache *cache.MapCache[string, []uint64]
var postListIdsCache *cache.MapCache[string, dao.PostIds] var postListIdsCache *cache.MapCache[string, common.PostIds]
var searchPostIdsCache *cache.MapCache[string, dao.PostIds] var searchPostIdsCache *cache.MapCache[string, common.PostIds]
var maxPostIdCache *cache.SliceCache[uint64] var maxPostIdCache *cache.SliceCache[uint64]
var usersCache *cache.MapCache[uint64, models2.Users] var usersCache *cache.MapCache[uint64, models2.Users]
@ -34,36 +34,36 @@ func InitActionsCommonCache() {
c := config.Conf.Load() c := config.Conf.Load()
archivesCaches = &Arch{ archivesCaches = &Arch{
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
setCacheFunc: dao.Archives, setCacheFunc: common.Archives,
} }
searchPostIdsCache = cache.NewMapCacheByFn[string, dao.PostIds](dao.SearchPostIds, c.SearchPostCacheTime) searchPostIdsCache = cache.NewMapCacheByFn[string, common.PostIds](common.SearchPostIds, c.SearchPostCacheTime)
postListIdsCache = cache.NewMapCacheByFn[string, dao.PostIds](dao.SearchPostIds, c.PostListCacheTime) postListIdsCache = cache.NewMapCacheByFn[string, common.PostIds](common.SearchPostIds, c.PostListCacheTime)
monthPostsCache = cache.NewMapCacheByFn[string, []uint64](dao.MonthPost, c.MonthPostCacheTime) monthPostsCache = cache.NewMapCacheByFn[string, []uint64](common.MonthPost, c.MonthPostCacheTime)
postContextCache = cache.NewMapCacheByFn[uint64, dao.PostContext](dao.GetPostContext, c.ContextPostCacheTime) postContextCache = cache.NewMapCacheByFn[uint64, common.PostContext](common.GetPostContext, c.ContextPostCacheTime)
postsCache = cache.NewMapCacheByBatchFn[uint64, models2.Posts](dao.GetPostsByIds, c.PostDataCacheTime) postsCache = cache.NewMapCacheByBatchFn[uint64, models2.Posts](common.GetPostsByIds, c.PostDataCacheTime)
postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](dao.GetPostMetaByPostIds, c.PostDataCacheTime) postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](common.GetPostMetaByPostIds, c.PostDataCacheTime)
categoryCaches = cache.NewSliceCache[models2.TermsMy](dao.Categories, c.CategoryCacheTime) categoryCaches = cache.NewSliceCache[models2.TermsMy](common.Categories, c.CategoryCacheTime)
recentPostsCaches = cache.NewSliceCache[models2.Posts](dao.RecentPosts, c.RecentPostCacheTime) recentPostsCaches = cache.NewSliceCache[models2.Posts](common.RecentPosts, c.RecentPostCacheTime)
recentCommentsCaches = cache.NewSliceCache[models2.Comments](dao.RecentComments, c.RecentCommentsCacheTime) recentCommentsCaches = cache.NewSliceCache[models2.Comments](common.RecentComments, c.RecentCommentsCacheTime)
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](dao.PostComments, c.PostCommentsCacheTime) postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](common.PostComments, c.PostCommentsCacheTime)
maxPostIdCache = cache.NewSliceCache[uint64](dao.GetMaxPostId, c.MaxPostIdCacheTime) maxPostIdCache = cache.NewSliceCache[uint64](common.GetMaxPostId, c.MaxPostIdCacheTime)
usersCache = cache.NewMapCacheByFn[uint64, models2.Users](dao.GetUserById, c.UserInfoCacheTime) usersCache = cache.NewMapCacheByFn[uint64, models2.Users](common.GetUserById, c.UserInfoCacheTime)
usersNameCache = cache.NewMapCacheByFn[string, models2.Users](dao.GetUserByName, c.UserInfoCacheTime) usersNameCache = cache.NewMapCacheByFn[string, models2.Users](common.GetUserByName, c.UserInfoCacheTime)
commentsCache = cache.NewMapCacheByBatchFn[uint64, models2.Comments](dao.GetCommentByIds, c.CommentsCacheTime) commentsCache = cache.NewMapCacheByBatchFn[uint64, models2.Comments](common.GetCommentByIds, c.CommentsCacheTime)
} }
func ClearCache() { func ClearCache() {

View File

@ -0,0 +1,18 @@
/**
* These rules are needed for backwards compatibility.
* They should match the button element rules in the base theme.json file.
*/
.wp-block-button__link {
color: #ffffff;
background-color: #32373c;
border-radius: 9999px; /* 100% causes an oval, but any explicit but really high value retains the pill shape. */
/* This needs a low specificity so it won't override the rules from the button element if defined in theme.json. */
box-shadow: none;
text-decoration: none;
/* The extra 2px are added to size solids the same as the outline versions.*/
padding: calc(0.667em + 2px) calc(1.333em + 2px);
font-size: 1.125em;
}

View File

@ -0,0 +1,2 @@
/*! This file is auto-generated */
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}

View File

@ -42,3 +42,14 @@ func (t FsTemplate) Instance(name string, data any) render.Render {
Data: data, Data: data,
} }
} }
func IsTemplateIsExist(tml string) (r bool, err error) {
arr, err := TemplateFs.ReadDir(tml)
if err != nil {
return
}
if len(arr) > 0 {
r = true
}
return
}

View File

@ -1,6 +1,6 @@
{{ define "layout/base"}} {{ define "layout/base"}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN" class="no-js"> <html lang="{{"WPLANG"| getOption}}" class="no-js">
<head> <head>
{{template "layout/head" .}} {{template "layout/head" .}}
{{block "head" .}} {{block "head" .}}

View File

@ -1,5 +1,5 @@
{{define "layout/head"}} {{define "layout/head"}}
<meta charset="UTF-8"> <meta charset="{{"blog_charset"| getOption}}">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<link rel="profile" href="https://gmpg.org/xfn/11"> <link rel="profile" href="https://gmpg.org/xfn/11">
<link rel="pingback" href="/xmlrpc.php"> <link rel="pingback" href="/xmlrpc.php">