This commit is contained in:
xing 2023-06-13 12:02:46 +08:00
parent e3d57830b0
commit 282e0c26e0
4 changed files with 21 additions and 16 deletions

View File

@ -177,7 +177,7 @@ func calClass(h *wp.Handle, s string, _ ...any) string {
func videoHeader(h *wp.Handle) { func videoHeader(h *wp.Handle) {
h.PushComponentFilterFn("videoSetting", videoPlay) h.PushComponentFilterFn("videoSetting", videoPlay)
wp.CustomVideo(h) wp.CustomVideo(h, constraints.Home)
} }
func videoPlay(h *wp.Handle, _ string, a ...any) string { func videoPlay(h *wp.Handle, _ string, a ...any) string {

View File

@ -35,7 +35,6 @@ func CalComponents(h *Handle) {
}) })
for k, components := range componentss { for k, components := range componentss {
key := str.Join("calComponents-", h.scene, "-", k) key := str.Join("calComponents-", h.scene, "-", k)
key = h.ComponentFilterFnHook("calComponents", key, k)
ss := reload.GetAnyValMapBy("calComponents", key, h, func(h *Handle) []Components[string] { ss := reload.GetAnyValMapBy("calComponents", key, h, func(h *Handle) []Components[string] {
r := slice.FilterAndMap(components, func(t Components[string]) (Components[string], bool) { r := slice.FilterAndMap(components, func(t Components[string]) (Components[string], bool) {
fns, ok := h.componentHook[k] fns, ok := h.componentHook[k]
@ -88,15 +87,18 @@ func (h *Handle) PushComponents(scene, componentType string, components ...Compo
} }
func (h *Handle) PushGroupComponentStr(scene, componentType, name string, order int, strs ...string) { func (h *Handle) PushGroupComponentStr(scene, componentType, name string, order int, strs ...string) {
var components []Components[string] var component = Components[string]{
for _, val := range strs { Val: strings.Join(slice.FilterAndMap(strs, func(t string) (string, bool) {
components = append(components, Components[string]{ t = strings.Trim(t, "\n\r\t\v\x00")
Val: val, if t == "" {
Order: order, return "", false
Name: name, }
}) return t, true
}), "\n"),
Order: order,
Name: name,
} }
h.PushComponents(scene, componentType, components...) h.PushComponents(scene, componentType, component)
} }
func (h *Handle) PushCacheGroupHeadScript(scene, name string, order int, fns ...func(*Handle) string) { func (h *Handle) PushCacheGroupHeadScript(scene, name string, order int, fns ...func(*Handle) string) {

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/fthvgb1/wp-go/app/cmd/reload" "github.com/fthvgb1/wp-go/app/cmd/reload"
"github.com/fthvgb1/wp-go/app/pkg/cache" "github.com/fthvgb1/wp-go/app/pkg/cache"
"github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/pkg/logs" "github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/pkg/models" "github.com/fthvgb1/wp-go/app/pkg/models"
"github.com/fthvgb1/wp-go/app/wpconfig" "github.com/fthvgb1/wp-go/app/wpconfig"
@ -96,7 +95,7 @@ func GetVideoSetting(h *Handle, u string) (string, error) {
return script, nil return script, nil
} }
func CustomVideo(h *Handle) (ok bool) { func CustomVideo(h *Handle, scene ...string) (ok bool) {
mod, err := wpconfig.GetThemeMods(h.theme) mod, err := wpconfig.GetThemeMods(h.theme)
if err != nil { if err != nil {
logs.Error(err, "getThemeMods fail", h.theme) logs.Error(err, "getThemeMods fail", h.theme)
@ -144,7 +143,7 @@ func CustomVideo(h *Handle) (ok bool) {
{"wp-", ""}, {"wp-", ""},
})) }))
}) })
h.PushGroupFooterScript(constraints.Home, "wp-custom-header", 10, scripts[0:len(scripts)-2]...)
var tr = `<script id="wp-i18n-js-after"> var tr = `<script id="wp-i18n-js-after">
wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );
</script> </script>
@ -157,11 +156,15 @@ wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );
</script> </script>
<script src='/wp-includes/js/dist/a11y.min.js?ver=ecce20f002eda4c19664' id='wp-a11y-js'></script> <script src='/wp-includes/js/dist/a11y.min.js?ver=ecce20f002eda4c19664' id='wp-a11y-js'></script>
` `
h.PushFooterScript(constraints.Home, c := []Components[string]{
NewComponent("wp-a11y-js-translations", tr, true, 10, nil), NewComponent("wp-a11y-js-translations", tr, true, 10, nil),
NewComponent("VideoSetting", hs, true, 10, nil), NewComponent("VideoSetting", hs, true, 10, nil),
NewComponent("header-script", scripts[len(scripts)-1], true, 10, nil), NewComponent("header-script", scripts[len(scripts)-1], true, 10, nil),
) }
for _, s := range scene {
h.PushGroupFooterScript(s, "wp-custom-header", 10, scripts[0:len(scripts)-2]...)
h.PushFooterScript(s, c...)
}
ok = true ok = true
return return
} }

View File

@ -103,12 +103,12 @@ func InitHandle(fn func(*Handle), h *Handle) {
h.ginH = gin.H{} h.ginH = gin.H{}
fnMap = map[string]map[string]any{} fnMap = map[string]map[string]any{}
fnHook = map[string]map[string]any{} fnHook = map[string]map[string]any{}
fn(h)
v := apply.UsePlugins() v := apply.UsePlugins()
pluginFn, ok := v.(func(*Handle)) pluginFn, ok := v.(func(*Handle))
if ok { if ok {
pluginFn(h) pluginFn(h)
} }
fn(h)
h.C.Set("inited", true) h.C.Set("inited", true)
inited = true inited = true
return *h return *h