From 4760f65b9b6bef1d3b86e47880144bf90b581119 Mon Sep 17 00:00:00 2001 From: xing Date: Mon, 24 Apr 2023 21:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/actions/themehook.go | 4 +- internal/pkg/cache/cache.go | 12 +++--- internal/pkg/constraints/const.go | 30 +++++++------- internal/pkg/dao/common.go | 2 +- internal/theme/templateFuncs.go | 4 +- internal/theme/twentyfifteen/customheader.go | 19 ++++----- .../theme/twentyfifteen/layout/base.gohtml | 2 +- .../theme/twentyfifteen/layout/head.gohtml | 1 + internal/theme/twentyfifteen/twentyfifteen.go | 6 +-- .../theme/twentyseventeen/layout/base.gohtml | 4 +- .../theme/twentyseventeen/twentyseventeen.go | 4 +- internal/theme/wp/calclass.go | 12 ++++++ internal/theme/wp/customlogo.go | 9 +++++ internal/theme/wp/pipe.go | 30 +++++++------- internal/theme/wp/template.gohtml | 8 ---- internal/theme/wp/wp.go | 39 +++++++++++-------- 16 files changed, 104 insertions(+), 82 deletions(-) diff --git a/internal/actions/themehook.go b/internal/actions/themehook.go index 244351b..6e0cb63 100644 --- a/internal/actions/themehook.go +++ b/internal/actions/themehook.go @@ -7,7 +7,7 @@ import ( "github.com/gin-gonic/gin" ) -func ThemeHook(scene int) func(*gin.Context) { +func ThemeHook(scene string) func(*gin.Context) { return func(c *gin.Context) { s := scene if scene == constraints.Home { @@ -19,6 +19,8 @@ func ThemeHook(scene int) func(*gin.Context) { h := wp.NewHandle(c, s, t) h.Index = wp.NewIndexHandle(h) h.Detail = wp.NewDetailHandle(h) + templ, _ := theme.GetTemplate(t) + h.SetTemplate(templ) theme.Hook(t, h) } } diff --git a/internal/pkg/cache/cache.go b/internal/pkg/cache/cache.go index 3719c94..2a8378d 100644 --- a/internal/pkg/cache/cache.go +++ b/internal/pkg/cache/cache.go @@ -14,7 +14,7 @@ import ( ) var postContextCache *cache.MapCache[uint64, dao.PostContext] -var categoryAndTagsCaches *cache.MapCache[int, []models.TermsMy] +var categoryAndTagsCaches *cache.MapCache[string, []models.TermsMy] var recentPostsCaches *cache.VarCache[[]models.Posts] var recentCommentsCaches *cache.VarCache[[]models.Comments] var postCommentCaches *cache.MapCache[uint64, []uint64] @@ -56,7 +56,7 @@ func InitActionsCommonCache() { postMetaCache = cachemanager.MapBatchCacheBy(dao.GetPostMetaByPostIds, c.CacheTime.PostDataCacheTime) - categoryAndTagsCaches = cachemanager.MapCacheBy[int](dao.CategoriesAndTags, c.CacheTime.CategoryCacheTime) + categoryAndTagsCaches = cachemanager.MapCacheBy[string](dao.CategoriesAndTags, c.CacheTime.CategoryCacheTime) recentPostsCaches = cache.NewVarCache(dao.RecentPosts, c.CacheTime.RecentPostCacheTime) @@ -117,8 +117,8 @@ func Archives(ctx context.Context) []models.PostArchive { // CategoriesTags categories or tags // // t is constraints.Tag or constraints.Category -func CategoriesTags(ctx context.Context, t ...int) []models.TermsMy { - tt := 0 +func CategoriesTags(ctx context.Context, t ...string) []models.TermsMy { + tt := "" if len(t) > 0 { tt = t[0] } @@ -126,8 +126,8 @@ func CategoriesTags(ctx context.Context, t ...int) []models.TermsMy { logs.IfError(err, "get category fail") return r } -func AllCategoryTagsNames(ctx context.Context, t ...int) map[string]struct{} { - tt := 0 +func AllCategoryTagsNames(ctx context.Context, t ...string) map[string]struct{} { + tt := "" if len(t) > 0 { tt = t[0] } diff --git a/internal/pkg/constraints/const.go b/internal/pkg/constraints/const.go index b2d368b..b293b07 100644 --- a/internal/pkg/constraints/const.go +++ b/internal/pkg/constraints/const.go @@ -1,23 +1,23 @@ package constraints const ( - Home = iota + 1 - Archive - Category - Tag - Search - Author - Detail + Home = "Home" + Archive = "Archive" + Category = "Category" + Tag = "Tag" + Search = "Search" + Author = "Author" + Detail = "Detail" - Ok - Error404 - ParamError - InternalErr - AllStats - AllScene + Ok = "Ok" + Error404 = "Error404" + ParamError = "ParamError" + InternalErr = "InternalErr" + AllStats = "AllStats" + AllScene = "AllScene" - PipData - PipRender + PipeData = "PipeData" + PipeRender = "PipeRender" Defaults = "default" diff --git a/internal/pkg/dao/common.go b/internal/pkg/dao/common.go index a34d69b..f0cae1f 100644 --- a/internal/pkg/dao/common.go +++ b/internal/pkg/dao/common.go @@ -23,7 +23,7 @@ type PostContext struct { func CategoriesAndTags(a ...any) (terms []models.TermsMy, err error) { ctx := a[0].(context.Context) - t, ok := a[1].(int) + t, ok := a[1].(string) var in = []any{"category", "post_tag"} if ok { switch t { diff --git a/internal/theme/templateFuncs.go b/internal/theme/templateFuncs.go index 0b5ce9c..85c6acd 100644 --- a/internal/theme/templateFuncs.go +++ b/internal/theme/templateFuncs.go @@ -22,8 +22,8 @@ var comFn = template.FuncMap{ }, "getLang": wpconfig.GetLang, "postsFn": postsFn, - "exec": func(fn func() string) string { - return fn() + "exec": func(fn func() string) template.HTML { + return template.HTML(fn()) }, } diff --git a/internal/theme/twentyfifteen/customheader.go b/internal/theme/twentyfifteen/customheader.go index 338cd50..2894791 100644 --- a/internal/theme/twentyfifteen/customheader.go +++ b/internal/theme/twentyfifteen/customheader.go @@ -108,15 +108,16 @@ func calCustomHeader(h *wp.Handle) (r string, rand bool) { return } -func customHeader(h *wp.Handle) { - headers := header.Load() - if headers == constraints.Defaults { - headerss, rand := calCustomHeader(h) - headers = headerss - if !rand { - header.Store(headers) +func customHeader(h *wp.Handle) func() string { + return func() string { + headers := header.Load() + if headers == constraints.Defaults { + headerss, rand := calCustomHeader(h) + headers = headerss + if !rand { + header.Store(headers) + } } + return headers } - h.SetData("customHeader", headers) - return } diff --git a/internal/theme/twentyfifteen/layout/base.gohtml b/internal/theme/twentyfifteen/layout/base.gohtml index 9fbca4f..40e3341 100644 --- a/internal/theme/twentyfifteen/layout/base.gohtml +++ b/internal/theme/twentyfifteen/layout/base.gohtml @@ -13,7 +13,7 @@