Compare commits

..

2 Commits

Author SHA1 Message Date
xing
1b1e3bf8f3 优化 2023-02-26 22:20:20 +08:00
xing
5ae0ad646e 优化 2023-02-26 22:03:30 +08:00
3 changed files with 29 additions and 29 deletions

View File

@ -11,16 +11,6 @@ import (
"strings" "strings"
) )
var commonClass = map[int]string{
constraints.Home: "home blog ",
constraints.Archive: "archive date ",
constraints.Category: "archive category ",
constraints.Tag: "archive category ",
constraints.Search: "search ",
constraints.Author: "archive author ",
constraints.Detail: "post-template-default single single-post ",
}
func (h *Handle) CalBodyClass() { func (h *Handle) CalBodyClass() {
h.GinH["bodyClass"] = h.BodyClass(h.Class...) h.GinH["bodyClass"] = h.BodyClass(h.Class...)
} }
@ -30,13 +20,21 @@ func (h *Handle) BodyClass(class ...string) string {
return "error404" return "error404"
} }
switch h.Scene { switch h.Scene {
case constraints.Home:
class = append(class, "home", "blog")
case constraints.Archive:
class = append(class, "archive", "date")
case constraints.Search: case constraints.Search:
s := "search-no-results" s := "search-no-results"
if len(h.Index.Posts) > 0 { if len(h.Index.Posts) > 0 {
s = "search-results" s = "search-results"
} }
class = append(class, s) class = append(class, "search", s)
case constraints.Category, constraints.Tag: case constraints.Category, constraints.Tag:
class = append(class, "archive", "category")
cat := h.Index.Param.Category cat := h.Index.Param.Category
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool { _, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool {
return my.Name == cat return my.Name == cat
@ -47,6 +45,7 @@ func (h *Handle) BodyClass(class ...string) string {
class = append(class, str.Join("category-", number.ToString(cate.Terms.TermId))) class = append(class, str.Join("category-", number.ToString(cate.Terms.TermId)))
case constraints.Author: case constraints.Author:
class = append(class, "archive", "author")
author := h.Index.Param.Author author := h.Index.Param.Author
user, _ := cache.GetUserByName(h.C, author) user, _ := cache.GetUserByName(h.C, author)
class = append(class, str.Join("author-", number.ToString(user.Id))) class = append(class, str.Join("author-", number.ToString(user.Id)))
@ -55,6 +54,7 @@ func (h *Handle) BodyClass(class ...string) string {
} }
case constraints.Detail: case constraints.Detail:
class = append(class, "post-template-default", "single", "single-post")
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id))) class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 { if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 {
class = append(class, "single-format-standard") class = append(class, "single-format-standard")
@ -69,6 +69,5 @@ func (h *Handle) BodyClass(class ...string) string {
if h.ThemeMods.ThemeSupport.ResponsiveEmbeds { if h.ThemeMods.ThemeSupport.ResponsiveEmbeds {
class = append(class, "wp-embed-responsive") class = append(class, "wp-embed-responsive")
} }
class = append(class, strings.Fields(commonClass[h.Scene])...) return strings.Join(class, " ")
return strings.Join(slice.Reverse(class), " ")
} }

View File

@ -28,7 +28,7 @@ type Handle struct {
Class []string Class []string
Scripts map[string][]func(*Handle) string Scripts map[string][]func(*Handle) string
ThemeMods wpconfig.ThemeMods ThemeMods wpconfig.ThemeMods
HandleFns []func(*Handle) HandleFns []HandleFn[*Handle]
} }
func NewHandle(c *gin.Context, scene int, theme string) *Handle { func NewHandle(c *gin.Context, scene int, theme string) *Handle {
@ -47,11 +47,11 @@ func NewHandle(c *gin.Context, scene int, theme string) *Handle {
} }
} }
func (h *Handle) PushHandleFn(fns ...func(*Handle)) { func (h *Handle) PushHandleFn(fns ...HandleFn[*Handle]) {
h.HandleFns = append(h.HandleFns, fns...) h.HandleFns = append(h.HandleFns, fns...)
} }
func (h *Handle) AutoCal(name string, fn func(*Handle) string) { func (h *Handle) PlushComponent(name string, fn func(*Handle) string) {
v, ok := reload.GetStr(name) v, ok := reload.GetStr(name)
if !ok { if !ok {
v = fn(h) v = fn(h)
@ -86,7 +86,7 @@ func (h *Handle) Render() {
fn(h) fn(h)
} }
h.PushHeadScript(constraints.HeadScript, CalSiteIcon, CalCustomCss) h.PushHeadScript(constraints.HeadScript, CalSiteIcon, CalCustomCss)
h.AutoCal("customLogo", CalCustomLogo) h.PlushComponent("customLogo", CalCustomLogo)
h.CalMultipleScript() h.CalMultipleScript()
h.CalBodyClass() h.CalBodyClass()

View File

@ -50,7 +50,10 @@ func pagination[T Model](db dbQuery, ctx context.Context, q QueryCondition) (r [
} }
q.Offset = offset q.Offset = offset
m := ctx.Value("handle=>") m := ctx.Value("handle=>")
if m != nil { if m == nil {
r, err = finds[T](db, ctx, q)
return
}
mm, ok := m.(string) mm, ok := m.(string)
if ok && mm == "toMap" { if ok && mm == "toMap" {
v := ctx.Value("map") v := ctx.Value("map")
@ -63,8 +66,6 @@ func pagination[T Model](db dbQuery, ctx context.Context, q QueryCondition) (r [
*vv = mx *vv = mx
return return
} }
}
r, err = finds[T](db, ctx, q)
return return
} }