fix bug 优化

This commit is contained in:
xing 2023-03-17 13:35:22 +08:00
parent ca94295eb7
commit 3f96c09d36
4 changed files with 19 additions and 37 deletions

View File

@ -34,13 +34,13 @@ func Init(fs embed.FS) {
logs.ErrPrintln(err, "解析colorscheme失败")
}
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(dispatch)...)
var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready)...)
func Hook(h *wp.Handle) {
pipe(h)
}
func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
components.WidgetArea(h)
h.GetPassword()
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string) string {
@ -50,18 +50,7 @@ func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
h.PushCacheGroupHeadScript("CalCustomBackGround", 10, CalCustomBackGround, colorSchemeCss)
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
switch h.Scene() {
case constraints.Detail:
detail(next, h.Detail)
default:
index(next, h.Index)
}
}
func index(next wp.HandleFn[*wp.Handle], i *wp.IndexHandle) {
i.Indexs()
}
func detail(fn wp.HandleFn[*wp.Handle], d *wp.DetailHandle) {
d.Details()
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.Indexs, 100))
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.Details, 100))
next(h)
}

View File

@ -101,8 +101,6 @@ func (d *DetailHandle) ContextPost() {
}
func (d *DetailHandle) Render() {
PreCodeAndStats(d.Handle)
PreTemplate(d.Handle)
reply := ""
if d.Post.CommentStatus == "open" && wpconfig.GetOption("thread_comments") == "1" {
reply = `<script src='/wp-includes/js/comment-reply.min.js' id='comment-reply-js'></script>`
@ -118,7 +116,8 @@ func (d *DetailHandle) Render() {
d.Handle.Render()
}
func (d *DetailHandle) Details() {
_ = d.BuildDetailData()
d.Render()
func Details(h *Handle) {
_ = h.Detail.BuildDetailData()
PreCodeAndStats(h)
PreTemplate(h)
}

View File

@ -148,8 +148,6 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
}
func (i *IndexHandle) Render() {
PreCodeAndStats(i.Handle)
PreTemplate(i.Handle)
i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
i.ExecPostsPlugin()
i.Pagination()
@ -159,7 +157,11 @@ func (i *IndexHandle) Render() {
i.Handle.Render()
}
func (i *IndexHandle) Indexs() {
_ = i.BuildIndexData(NewIndexParams(i.C))
i.Render()
func Indexs(h *Handle) {
if h.Scene() != constraints.Detail {
i := h.Index
_ = i.BuildIndexData(NewIndexParams(i.C))
PreCodeAndStats(h)
PreTemplate(h)
}
}

View File

@ -1,7 +1,6 @@
package wp
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/maps"
"github.com/fthvgb1/wp-go/helper/slice"
str "github.com/fthvgb1/wp-go/helper/strings"
@ -229,10 +228,6 @@ func (h *Handle) PushGroupFooterScript(order int, fns ...string) {
h.PushGroupComponentStrs(constraints.FooterScript, order, fns...)
}
func (h *Handle) componentKey(name string) string {
return fmt.Sprintf("theme_%d_%s", h.scene, name)
}
func (h *Handle) PushCacheGroupFooterScript(key string, order int, fns ...func(*Handle) string) {
h.PushGroupCacheComponentFn(constraints.FooterScript, key, order, fns...)
}
@ -312,8 +307,7 @@ func (h *Handle) CommonComponents() {
}
func (h *Handle) PushComponents(name string, components ...Components) {
k := h.componentKey(name)
h.components[k] = append(h.components[k], components...)
h.components[name] = append(h.components[name], components...)
}
func (h *Handle) PushGroupComponentStrs(name string, order int, fns ...string) {
@ -324,8 +318,7 @@ func (h *Handle) PushGroupComponentStrs(name string, order int, fns ...string) {
Order: order,
})
}
k := h.componentKey(name)
h.components[k] = append(h.components[k], calls...)
h.components[name] = append(h.components[name], calls...)
}
func (h *Handle) PushGroupComponentFns(name string, order int, fns ...func(*Handle) string) {
var calls []Components
@ -335,8 +328,7 @@ func (h *Handle) PushGroupComponentFns(name string, order int, fns ...func(*Hand
Order: order,
})
}
k := h.componentKey(name)
h.components[k] = append(h.components[k], calls...)
h.components[name] = append(h.components[name], calls...)
}
func (h *Handle) CalMultipleComponents() {