优化完善
This commit is contained in:
parent
8da369b166
commit
8a9209196e
|
@ -14,6 +14,7 @@ const (
|
|||
ParamError
|
||||
InternalErr
|
||||
AllStats
|
||||
AllScene
|
||||
|
||||
Defaults = "default"
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func Init(fs embed.FS) {
|
|||
}
|
||||
}
|
||||
|
||||
var pipe = wp.HandlePipe(wp.ExecuteHandleFn, widget.MiddleWare(ready, data)...)
|
||||
var pipe = wp.HandlePipe(wp.ExecuteHandleFn, widget.MiddleWare(ready, wp.DataHandle)...)
|
||||
|
||||
func Hook(h *wp.Handle) {
|
||||
pipe(h)
|
||||
|
@ -53,16 +53,6 @@ func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
|||
next(h)
|
||||
}
|
||||
|
||||
func data(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
||||
if h.Scene() == constraints.Detail {
|
||||
wp.Details(h)
|
||||
} else {
|
||||
wp.Indexs(h)
|
||||
}
|
||||
h.DetermineHandleFns()
|
||||
next(h)
|
||||
}
|
||||
|
||||
func configs(h *wp.Handle) {
|
||||
conf := config.GetConfig()
|
||||
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string, args ...any) string {
|
||||
|
@ -73,11 +63,15 @@ func configs(h *wp.Handle) {
|
|||
h.PushCacheGroupHeadScript("CalCustomBackGround", 10, CalCustomBackGround, colorSchemeCss)
|
||||
h.CommonComponents()
|
||||
h.Index.SetListPlugin(wp.PostsPlugins(wp.PostPlugin(), wp.GetListPostPlugins(conf.ListPagePlugins, wp.ListPostPlugins())...))
|
||||
h.PushHandleFn(constraints.Ok, wp.NewHandleFn(components.WidgetArea, 20))
|
||||
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
|
||||
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50))
|
||||
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50))
|
||||
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(postThumb, 60))
|
||||
components.WidgetArea(h)
|
||||
h.PushRender(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
|
||||
h.PushRender(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50))
|
||||
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50))
|
||||
h.PushRender(constraints.Detail, wp.NewHandleFn(postThumb, 60))
|
||||
h.PushDataHandler(constraints.Detail, wp.NewHandleFn(wp.Details, 100))
|
||||
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.Indexs, 100))
|
||||
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreCodeAndStats, 80))
|
||||
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreTemplate, 70))
|
||||
}
|
||||
|
||||
func postThumb(h *wp.Handle) {
|
||||
|
|
|
@ -42,7 +42,7 @@ var paginate = func() plugins.PageEle {
|
|||
return p
|
||||
}()
|
||||
|
||||
var pipe = wp.HandlePipe(wp.ExecuteHandleFn, widget.MiddleWare(ready, data)...)
|
||||
var pipe = wp.HandlePipe(wp.ExecuteHandleFn, widget.MiddleWare(ready, wp.DataHandle)...)
|
||||
|
||||
func Hook(h *wp.Handle) {
|
||||
pipe(h)
|
||||
|
@ -55,20 +55,23 @@ func configs(h *wp.Handle) {
|
|||
h.PushCacheGroupHeadScript("colorScheme-customHeader", 10, colorScheme, customHeader)
|
||||
components.WidgetArea(h)
|
||||
pushScripts(h)
|
||||
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(func(h *wp.Handle) {
|
||||
h.PushRender(constraints.AllStats, wp.NewHandleFn(func(h *wp.Handle) {
|
||||
h.SetData("HeaderImage", getHeaderImage(h))
|
||||
}, 10))
|
||||
h.SetComponentsArgs(widgets.Widget, map[string]string{
|
||||
"{$before_widget}": `<section id="%s" class="%s">`,
|
||||
"{$after_widget}": `</section>`,
|
||||
})
|
||||
h.PushGroupHandleFn(constraints.AllStats, 90, wp.PreTemplate, errorsHandle)
|
||||
h.PushGroupRender(constraints.AllStats, 90, wp.PreTemplate, errorsHandle)
|
||||
h.CommonComponents()
|
||||
h.Index.SetPageEle(paginate)
|
||||
h.Index.SetListPlugin(wp.PostsPlugins(wp.PostPlugin(postThumbnail), wp.GetListPostPlugins(conf.ListPagePlugins, wp.ListPostPlugins())...))
|
||||
wp.SetComponentsArgsForMap(h, widgets.Search, "{$form}", searchForm)
|
||||
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 10))
|
||||
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 10))
|
||||
h.PushRender(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 10))
|
||||
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 10))
|
||||
h.PushDataHandler(constraints.Detail, wp.NewHandleFn(detail, 100))
|
||||
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(index, 100))
|
||||
h.PushDataHandler(constraints.AllScene, wp.NewHandleFn(wp.PreCodeAndStats, 90))
|
||||
}
|
||||
func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
||||
wp.InitThemeArgAndConfig(configs, h)
|
||||
|
@ -95,17 +98,6 @@ func errorsHandle(h *wp.Handle) {
|
|||
}
|
||||
}
|
||||
|
||||
func data(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
|
||||
if h.Scene() == constraints.Detail {
|
||||
detail(h)
|
||||
} else {
|
||||
index(h)
|
||||
}
|
||||
wp.PreCodeAndStats(h)
|
||||
h.DetermineHandleFns()
|
||||
next(h)
|
||||
}
|
||||
|
||||
func index(h *wp.Handle) {
|
||||
if h.Scene() == constraints.Detail {
|
||||
return
|
||||
|
|
|
@ -93,7 +93,7 @@ func (h *Handle) GetHeaderImages(theme string) (r []models.PostThumbnail, err er
|
|||
}
|
||||
|
||||
func thumb(m models.Posts, theme string) models.PostThumbnail {
|
||||
m.Thumbnail = wpconfig.Thumbnail(m.AttachmentMetadata, "thumbnail", "", "thumbnail", "post-thumbnail", fmt.Sprintf("%s-thumbnail-avatar", theme))
|
||||
m.Thumbnail = wpconfig.Thumbnail(m.AttachmentMetadata, "full", "", "thumbnail", "post-thumbnail", fmt.Sprintf("%s-thumbnail-avatar", theme))
|
||||
m.Thumbnail.Width = m.AttachmentMetadata.Width
|
||||
m.Thumbnail.Height = m.AttachmentMetadata.Height
|
||||
if m.Thumbnail.Path != "" {
|
||||
|
|
|
@ -116,6 +116,4 @@ func DetailRender(h *Handle) {
|
|||
|
||||
func Details(h *Handle) {
|
||||
_ = h.Detail.BuildDetailData()
|
||||
PreCodeAndStats(h)
|
||||
PreTemplate(h)
|
||||
}
|
||||
|
|
|
@ -153,8 +153,6 @@ func Indexs(h *Handle) {
|
|||
}
|
||||
i := h.Index
|
||||
_ = i.BuildIndexData(NewIndexParams(i.C))
|
||||
PreCodeAndStats(h)
|
||||
PreTemplate(h)
|
||||
}
|
||||
|
||||
func (i *IndexHandle) MarkSticky(posts *[]models.Posts) {
|
||||
|
|
|
@ -30,7 +30,8 @@ type Handle struct {
|
|||
templ string
|
||||
components map[string][]Components[string]
|
||||
themeMods wpconfig.ThemeMods
|
||||
handleFns map[int][]HandleCall
|
||||
renders map[int][]HandleCall
|
||||
dataHandler map[int][]HandleCall
|
||||
err error
|
||||
abort bool
|
||||
componentsArgs map[string]any
|
||||
|
@ -69,7 +70,8 @@ func InitThemeArgAndConfig(fn func(*Handle), h *Handle) {
|
|||
var inited = false
|
||||
hh := reload.GetAnyValBys("themeArgAndConfig", h, func(h *Handle) Handle {
|
||||
h.components = make(map[string][]Components[string])
|
||||
h.handleFns = make(map[int][]HandleCall)
|
||||
h.renders = make(map[int][]HandleCall)
|
||||
h.dataHandler = make(map[int][]HandleCall)
|
||||
h.componentsArgs = make(map[string]any)
|
||||
h.componentFilterFn = make(map[string][]func(*Handle, string, ...any) string)
|
||||
h.ginH = gin.H{}
|
||||
|
@ -97,7 +99,8 @@ func InitThemeArgAndConfig(fn func(*Handle), h *Handle) {
|
|||
h.Index.postsPlugin = hh.Index.postsPlugin
|
||||
h.Index.pageEle = hh.Index.pageEle
|
||||
h.Detail.CommentRender = hh.Detail.CommentRender
|
||||
h.handleFns = hh.handleFns
|
||||
h.renders = hh.renders
|
||||
h.dataHandler = hh.dataHandler
|
||||
h.componentsArgs = hh.componentsArgs
|
||||
h.componentFilterFn = hh.componentFilterFn
|
||||
}
|
||||
|
@ -227,16 +230,45 @@ func (h *Handle) NewCacheComponent(name string, order int, fn func(handle *Handl
|
|||
return Components[string]{Fn: fn, CacheKey: name, Order: order}
|
||||
}
|
||||
|
||||
func (h *Handle) PushHandleFn(statsOrScene int, fns ...HandleCall) {
|
||||
h.handleFns[statsOrScene] = append(h.handleFns[statsOrScene], fns...)
|
||||
func (h *Handle) PushRender(statsOrScene int, fns ...HandleCall) {
|
||||
h.renders[statsOrScene] = append(h.renders[statsOrScene], fns...)
|
||||
}
|
||||
func (h *Handle) PushDataHandler(Scene int, fns ...HandleCall) {
|
||||
h.dataHandler[Scene] = append(h.dataHandler[Scene], fns...)
|
||||
}
|
||||
|
||||
func (h *Handle) PushGroupHandleFn(statsOrScene, order int, fns ...HandleFn[*Handle]) {
|
||||
func (h *Handle) PushGroupRender(statsOrScene, order int, fns ...HandleFn[*Handle]) {
|
||||
var calls []HandleCall
|
||||
for _, fn := range fns {
|
||||
calls = append(calls, HandleCall{fn, order})
|
||||
}
|
||||
h.handleFns[statsOrScene] = append(h.handleFns[statsOrScene], calls...)
|
||||
h.renders[statsOrScene] = append(h.renders[statsOrScene], calls...)
|
||||
}
|
||||
func (h *Handle) PushGroupDataHandler(scene, order int, fns ...HandleFn[*Handle]) {
|
||||
var calls []HandleCall
|
||||
for _, fn := range fns {
|
||||
calls = append(calls, HandleCall{fn, order})
|
||||
}
|
||||
h.dataHandler[scene] = append(h.dataHandler[scene], calls...)
|
||||
}
|
||||
|
||||
func DataHandle(next HandleFn[*Handle], h *Handle) {
|
||||
handlers := reload.SafetyMapBy("dataHandle", h.scene, h, func(h *Handle) []HandleCall {
|
||||
a := h.dataHandler[h.scene]
|
||||
aa, ok := h.dataHandler[constraints.AllScene]
|
||||
if ok {
|
||||
a = append(a, aa...)
|
||||
}
|
||||
slice.Sort(a, func(i, j HandleCall) bool {
|
||||
return i.Order > j.Order
|
||||
})
|
||||
return a
|
||||
})
|
||||
for _, handler := range handlers {
|
||||
handler.Fn(h)
|
||||
}
|
||||
h.DetermineHandleFns()
|
||||
next(h)
|
||||
}
|
||||
|
||||
func (h *Handle) AddCacheComponent(name string, fn func(*Handle) string) {
|
||||
|
@ -280,16 +312,16 @@ func (h *Handle) GetPassword() {
|
|||
}
|
||||
|
||||
func (h *Handle) ExecHandleFns() {
|
||||
calls, ok := h.handleFns[h.Stats]
|
||||
calls, ok := h.renders[h.Stats]
|
||||
var fns []HandleCall
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
calls, ok = h.handleFns[h.scene]
|
||||
calls, ok = h.renders[h.scene]
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
calls, ok = h.handleFns[constraints.AllStats]
|
||||
calls, ok = h.renders[constraints.AllStats]
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
|
@ -334,8 +366,8 @@ func (h *Handle) Render() {
|
|||
func (h *Handle) CommonComponents() {
|
||||
h.AddCacheComponent("customLogo", CalCustomLogo)
|
||||
h.PushCacheGroupHeadScript("siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
|
||||
h.PushGroupHandleFn(constraints.AllStats, 10, CalComponents)
|
||||
h.PushHandleFn(constraints.AllStats, NewHandleFn(func(h *Handle) {
|
||||
h.PushGroupRender(constraints.AllStats, 10, CalComponents)
|
||||
h.PushRender(constraints.AllStats, NewHandleFn(func(h *Handle) {
|
||||
h.C.HTML(h.Code, h.templ, h.ginH)
|
||||
}, 0))
|
||||
}
|
||||
|
@ -406,16 +438,20 @@ func HandlePipe[T any](initial func(T), fns ...HandlePipeFn[T]) HandleFn[T] {
|
|||
}
|
||||
|
||||
func DetermineHandleFn(h *Handle) []HandleCall {
|
||||
calls, ok := h.handleFns[h.Stats]
|
||||
calls, ok := h.renders[h.Stats]
|
||||
var fns []HandleCall
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
calls, ok = h.handleFns[h.scene]
|
||||
calls, ok = h.renders[h.scene]
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
calls, ok = h.handleFns[constraints.AllStats]
|
||||
calls, ok = h.renders[constraints.AllStats]
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
calls, ok = h.renders[constraints.AllScene]
|
||||
if ok {
|
||||
fns = append(fns, calls...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user