diff --git a/app/theme/twentyfifteen/twentyfifteen.go b/app/theme/twentyfifteen/twentyfifteen.go index 8ac84c6..cb40476 100644 --- a/app/theme/twentyfifteen/twentyfifteen.go +++ b/app/theme/twentyfifteen/twentyfifteen.go @@ -28,7 +28,6 @@ func configs(h *wp.Handle) { h.PushCacheGroupHeadScript(constraints.AllScene, "colorSchemeCss", 10.0056, colorSchemeCss) h.CommonComponents() components.WidgetArea(h) - wp.ReplyCommentJs(h) h.SetData("customHeader", customHeader(h)) wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(wp.IndexRender, 50.005, "wp.IndexRender")) h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50.005, "wp.DetailRender")) diff --git a/app/theme/twentyseventeen/twentyseventeen.go b/app/theme/twentyseventeen/twentyseventeen.go index 6cbf588..716130d 100644 --- a/app/theme/twentyseventeen/twentyseventeen.go +++ b/app/theme/twentyseventeen/twentyseventeen.go @@ -69,7 +69,6 @@ func configs(h *wp.Handle) { h.SetData("colophon", colophon) setPaginationAndRender(h) h.CommonComponents() - wp.ReplyCommentJs(h) h.PushPostPlugin(postThumbnail) wp.SetComponentsArgsForMap(widgets.Search, "{$form}", searchForm) wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(wp.IndexRender, 10.005, "wp.IndexRender")) diff --git a/app/theme/wp/components.go b/app/theme/wp/components.go index 195db76..6f7905e 100644 --- a/app/theme/wp/components.go +++ b/app/theme/wp/components.go @@ -39,24 +39,21 @@ func (h *Handle) HookComponents(scene string, fn func(Components[string]) (Compo handleComponentHook.Store(scene, v) } -var getComponentFn = reload.BuildMapFn[string]("scene-components", getComponent) -var hookComponentFn = reload.BuildMapFn[string]("calComponents", hookComponent) +var GetComponents = reload.BuildMapFn[string]("scene-components", getComponent) +var HookComponents = reload.BuildMapFnWithAnyParams[string]("calComponents", hookComponent) -type componentParam struct { - components []Components[string] - k string -} - -func hookComponent(p componentParam) []Components[string] { +func hookComponent(a ...any) []Components[string] { + k := a[0].(string) + components := a[1].([]Components[string]) mut := reload.GetGlobeMutex() mut.Lock() - allHooks := slice.FilterAndToMap(p.components, func(t Components[string], _ int) (string, []func(Components[string]) (Components[string], bool), bool) { - fn, ok := handleComponentHook.Load(p.k) - return p.k, fn, ok + allHooks := slice.FilterAndToMap(components, func(t Components[string], _ int) (string, []func(Components[string]) (Components[string], bool), bool) { + fn, ok := handleComponentHook.Load(k) + return k, fn, ok }) mut.Unlock() - r := slice.FilterAndMap(p.components, func(component Components[string]) (Components[string], bool) { - hooks, ok := allHooks[p.k] + r := slice.FilterAndMap(components, func(component Components[string]) (Components[string], bool) { + hooks, ok := allHooks[k] if !ok { return component, true } @@ -100,10 +97,10 @@ func cacheComponentFn(a cacheComponentParm[string]) string { } func CalComponents(h *Handle) { - allComponents := getComponentFn(str.Join("allScene-", h.scene), h) + allComponents := GetComponents(str.Join("allScene-", h.scene), h) for k, components := range allComponents { key := str.Join("calComponents-", h.scene, "-", k) - hookedComponents := hookComponentFn(key, componentParam{components, k}) + hookedComponents := HookComponents(key, k, components) var s = make([]string, 0, len(hookedComponents)) for _, component := range hookedComponents { if component.Val != "" { diff --git a/app/theme/wp/wp.go b/app/theme/wp/wp.go index d629da3..1d7b37a 100644 --- a/app/theme/wp/wp.go +++ b/app/theme/wp/wp.go @@ -248,6 +248,7 @@ func (h *Handle) CommonComponents() { h.PushCacheGroupHeadScript(constraints.AllScene, "siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss) h.PushRender(constraints.AllStats, NewHandleFn(CalComponents, 10.001, "wp.CalComponents")) h.PushRender(constraints.AllStats, NewHandleFn(PreRenderTemplate, 0, "wp.PreRenderTemplate")) + ReplyCommentJs(h) AdditionScript(h) } diff --git a/cache/reload/reload.go b/cache/reload/reload.go index 918d91b..547e166 100644 --- a/cache/reload/reload.go +++ b/cache/reload/reload.go @@ -132,7 +132,7 @@ func BuildMapFnWithAnyParams[K comparable, V any](namespace string, fn func(...a if ok { return v } - v = fn(a) + v = fn(a...) m.Val.Store(key, v) return v }