Compare commits

...

2 Commits

Author SHA1 Message Date
1ecb338af5 主题配置复制 2023-04-02 23:37:12 +08:00
7e55253126 小优化 2023-03-31 14:33:09 +08:00
3 changed files with 26 additions and 5 deletions

View File

@ -12,7 +12,7 @@ import (
)
func CalBodyClass(h *Handle) {
h.ginH["bodyClass"] = h.BodyClass(h.class...)
h.ginH["bodyClass"] = h.BodyClass(h.bodyClass...)
}
func (h *Handle) BodyClass(class ...string) string {

View File

@ -70,7 +70,6 @@ func Search(h *wp.Handle, id string) string {
return args
})
args = maps.Copy(args)
s := strings.ReplaceAll(searchTemplate, "{$form}", form)
val := ""
if h.Scene() == constraints.Search {

View File

@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"net/http"
"strings"
"sync"
)
type Handle struct {
@ -26,7 +27,7 @@ type Handle struct {
Code int
Stats int
templ string
class []string
bodyClass []string
components map[string][]Components[string]
themeMods wpconfig.ThemeMods
handleFns map[int][]HandleCall
@ -36,6 +37,9 @@ type Handle struct {
componentFilterFn map[string][]func(*Handle, string, ...any) string
}
var configHandle = reload.Vars(&Handle{})
var configHandleMux = sync.Mutex{}
type HandlePlugins map[string]HandleFn[*Handle]
// Components Order 为执行顺序,降序执行
@ -55,6 +59,24 @@ type HandleCall struct {
Order int
}
func InitThemeArgAndConfig(fn func(*Handle) *Handle, h *Handle) {
hh := configHandle.Load()
if len(hh.handleFns) < 1 {
configHandleMux.Lock()
hh = configHandle.Load()
if len(hh.handleFns) < 1 {
hh = fn(h)
configHandle.Store(hh)
}
configHandleMux.Unlock()
}
h.components = hh.components
h.handleFns = hh.handleFns
h.componentsArgs = hh.componentsArgs
h.componentFilterFn = hh.componentFilterFn
h.ginH = maps.Copy(hh.ginH)
}
func (h *Handle) ComponentFilterFn(name string) ([]func(*Handle, string, ...any) string, bool) {
fn, ok := h.componentFilterFn[name]
return fn, ok
@ -109,7 +131,7 @@ func (h *Handle) SetData(k string, v any) {
}
func (h *Handle) PushClass(class ...string) {
h.class = append(h.class, class...)
h.bodyClass = append(h.bodyClass, class...)
}
func GetComponentsArgs[T any](h *Handle, k string, defaults T) T {
@ -202,7 +224,7 @@ func (h *Handle) PushGroupHandleFn(statsOrScene, order int, fns ...HandleFn[*Han
}
func (h *Handle) AddCacheComponent(name string, fn func(*Handle) string) {
h.ginH[name] = reload.GetAnyValBys(name, h, fn)
h.components[name] = append(h.components[name], h.NewCacheComponent(name, 10, fn))
}
func (h *Handle) PushHeadScript(fn ...Components[string]) {