重写body class机制
This commit is contained in:
parent
125764711d
commit
b53819f733
|
@ -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, " ")
|
||||
}
|
||||
|
|
|
@ -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, " "))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user