From 3f96c09d36662062765b66f5b269d1ab4dcbe85a Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 17 Mar 2023 13:35:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/twentyfifteen/twentyfifteen.go | 21 +++++-------------- internal/theme/wp/detail.go | 9 ++++---- internal/theme/wp/index.go | 12 ++++++----- internal/theme/wp/wp.go | 14 +++---------- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index 95dd7bc..ed17583 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -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) } diff --git a/internal/theme/wp/detail.go b/internal/theme/wp/detail.go index ef70f16..653ec86 100644 --- a/internal/theme/wp/detail.go +++ b/internal/theme/wp/detail.go @@ -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 = `` @@ -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) } diff --git a/internal/theme/wp/index.go b/internal/theme/wp/index.go index 99c119d..8226b89 100644 --- a/internal/theme/wp/index.go +++ b/internal/theme/wp/index.go @@ -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) + } } diff --git a/internal/theme/wp/wp.go b/internal/theme/wp/wp.go index 8677afb..81c6ea3 100644 --- a/internal/theme/wp/wp.go +++ b/internal/theme/wp/wp.go @@ -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() {