From b53819f733bad2aba1c77edd1104a676da94c37b Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 15 Apr 2023 13:22:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99body=20class=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/twentyseventeen/twentyseventeen.go | 8 ++++---- internal/theme/wp/bodyclass.go | 7 ++++--- internal/theme/wp/wp.go | 5 ----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index fb91281..9a876cc 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -51,7 +51,7 @@ func Hook(h *wp.Handle) { func configs(h *wp.Handle) { conf := config.GetConfig() wphandle.RegisterPlugins(h, conf.Plugins...) - h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(calClass, 20)) + h.PushComponentFilterFn("bodyClass", calClass) h.PushCacheGroupHeadScript("colorScheme-customHeader", 10, colorScheme, customHeader) components.WidgetArea(h) pushScripts(h) @@ -185,10 +185,10 @@ func getHeaderImage(h *wp.Handle) (r models.PostThumbnail) { return } -func calClass(h *wp.Handle) { +func calClass(h *wp.Handle, s string, a ...any) string { + class := strings.Split(s, " ") themeMods := h.CommonThemeMods() u := wpconfig.GetThemeModsVal(ThemeName, "header_image", themeMods.ThemeSupport.CustomHeader.DefaultImage) - var class []string if u != "" && u != "remove-header" { class = append(class, "has-header-image") } @@ -207,5 +207,5 @@ func calClass(h *wp.Handle) { class = append(class, "page-two-column") } } - h.PushClass(class...) + return strings.Join(class, " ") } diff --git a/internal/theme/wp/bodyclass.go b/internal/theme/wp/bodyclass.go index f06d6c7..0bdaa7e 100644 --- a/internal/theme/wp/bodyclass.go +++ b/internal/theme/wp/bodyclass.go @@ -12,10 +12,11 @@ import ( ) func CalBodyClass(h *Handle) { - h.ginH["bodyClass"] = h.BodyClass(h.bodyClass...) + h.ginH["bodyClass"] = h.BodyClass() } -func (h *Handle) BodyClass(class ...string) string { +func (h *Handle) BodyClass() string { + var class []string if constraints.Ok != h.Stats { class = append(class, "error404") } @@ -72,5 +73,5 @@ func (h *Handle) BodyClass(class ...string) string { if h.themeMods.ThemeSupport.ResponsiveEmbeds { class = append(class, "wp-embed-responsive") } - return strings.Join(class, " ") + return h.ComponentFilterFnHook("bodyClass", strings.Join(class, " ")) } diff --git a/internal/theme/wp/wp.go b/internal/theme/wp/wp.go index a97edd0..c5a7937 100644 --- a/internal/theme/wp/wp.go +++ b/internal/theme/wp/wp.go @@ -27,7 +27,6 @@ type Handle struct { Code int Stats int templ string - bodyClass []string components map[string][]Components[string] themeMods wpconfig.ThemeMods handleFns map[int][]HandleCall @@ -149,10 +148,6 @@ func (h *Handle) SetData(k string, v any) { h.ginH[k] = v } -func (h *Handle) PushClass(class ...string) { - h.bodyClass = append(h.bodyClass, class...) -} - func GetComponentsArgs[T any](h *Handle, k string, defaults T) T { v, ok := h.componentsArgs[k] if ok {