From 49b51dadcb521059ee0c95f458b9d64550f81f52 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 16 Feb 2023 22:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20bodyclass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/bodyclass.go | 22 +++------------------- internal/theme/theme.go | 1 - 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/internal/theme/common/bodyclass.go b/internal/theme/common/bodyclass.go index be2f386..acadccd 100644 --- a/internal/theme/common/bodyclass.go +++ b/internal/theme/common/bodyclass.go @@ -2,7 +2,6 @@ package common import ( "fmt" - "github.com/fthvgb1/wp-go/helper/maps" "github.com/fthvgb1/wp-go/helper/slice" str "github.com/fthvgb1/wp-go/helper/strings" "github.com/fthvgb1/wp-go/internal/pkg/cache" @@ -21,22 +20,6 @@ var commonClass = map[int]string{ constraints.Detail: "post-template-default single single-post ", } -type Support map[string]struct{} - -var themeSupport = map[string]Support{} - -func AddThemeSupport(theme string, support Support) { - themeSupport[theme] = support -} - -func (h *Handle) IsSupport(name string) bool { - m, ok := themeSupport[h.Theme] - if ok { - return maps.IsExists(m, name) - } - return ok -} - func (h *Handle) CalBodyClass() { h.GinH["bodyClass"] = h.bodyClass(h.Class...) } @@ -46,6 +29,7 @@ func (h *Handle) bodyClass(class ...string) string { if constraints.Ok != h.Stats { return "error404" } + mods, err := wpconfig.GetThemeMods(h.Theme) switch h.Scene { case constraints.Search: s = "search-no-results" @@ -66,12 +50,12 @@ func (h *Handle) bodyClass(class ...string) string { s = fmt.Sprintf("category-%v category-%v", s, cate.Terms.TermId) case constraints.Detail: s = fmt.Sprintf("postid-%d", h.GinH["post"].(models.Posts).Id) - if h.IsSupport("post-formats") { + if len(mods.ThemeSupport.PostFormats) > 0 { s = str.Join(s, " single-format-standard") } } class = append(class, s) - mods, err := wpconfig.GetThemeMods(h.Theme) + if err == nil { if wpconfig.IsCustomBackground(h.Theme) { class = append(class, "custom-background") diff --git a/internal/theme/theme.go b/internal/theme/theme.go index 0f3b5b3..3a5fe99 100644 --- a/internal/theme/theme.go +++ b/internal/theme/theme.go @@ -11,7 +11,6 @@ import ( func InitTheme() { addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook) addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook) - common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport()) } func Reload() {