From e03194b7687b5315202f5bbf38d2303fe9165e46 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 14 Mar 2023 19:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=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 | 2 +- internal/theme/twentyseventeen/twentyseventeen.go | 3 ++- internal/theme/wp/components/widget/middleware.go | 9 +++++++++ internal/theme/wp/detail.go | 4 ++-- internal/theme/wp/index.go | 4 ++-- internal/theme/wp/wp.go | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 internal/theme/wp/components/widget/middleware.go diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index af9f0e9..58b922a 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -34,7 +34,7 @@ func Init(fs embed.FS) { logs.ErrPrintln(err, "解析colorscheme失败") } -var pipe = wp.HandlePipe(wp.Render, widget.IsCategory, dispatch) +var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(dispatch)...) func Hook(h *wp.Handle) { pipe(h) diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index 2f47bbc..d350eb6 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -16,6 +16,7 @@ import ( "github.com/fthvgb1/wp-go/internal/plugins/wphandle" "github.com/fthvgb1/wp-go/internal/theme/wp" "github.com/fthvgb1/wp-go/internal/theme/wp/components" + "github.com/fthvgb1/wp-go/internal/theme/wp/components/widget" "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/gin-gonic/gin" "strings" @@ -41,7 +42,7 @@ var paginate = func() plugins.PageEle { return p }() -var pipe = wp.HandlePipe(wp.Render, ready, dispatch) +var pipe = wp.HandlePipe(wp.Render, widget.MiddleWare(ready, dispatch)...) func Hook(h *wp.Handle) { pipe(h) diff --git a/internal/theme/wp/components/widget/middleware.go b/internal/theme/wp/components/widget/middleware.go new file mode 100644 index 0000000..718e853 --- /dev/null +++ b/internal/theme/wp/components/widget/middleware.go @@ -0,0 +1,9 @@ +package widget + +import "github.com/fthvgb1/wp-go/internal/theme/wp" + +func MiddleWare(call ...wp.HandlePipeFn[*wp.Handle]) []wp.HandlePipeFn[*wp.Handle] { + return append([]wp.HandlePipeFn[*wp.Handle]{ + IsCategory, + }, call...) +} diff --git a/internal/theme/wp/detail.go b/internal/theme/wp/detail.go index 4a7beb8..ef70f16 100644 --- a/internal/theme/wp/detail.go +++ b/internal/theme/wp/detail.go @@ -101,8 +101,8 @@ func (d *DetailHandle) ContextPost() { } func (d *DetailHandle) Render() { - d.PreCodeAndStats() - d.PreTemplate() + PreCodeAndStats(d.Handle) + PreTemplate(d.Handle) reply := "" if d.Post.CommentStatus == "open" && wpconfig.GetOption("thread_comments") == "1" { reply = `` diff --git a/internal/theme/wp/index.go b/internal/theme/wp/index.go index 20b5f00..99c119d 100644 --- a/internal/theme/wp/index.go +++ b/internal/theme/wp/index.go @@ -148,8 +148,8 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) { } func (i *IndexHandle) Render() { - i.PreCodeAndStats() - i.PreTemplate() + PreCodeAndStats(i.Handle) + PreTemplate(i.Handle) i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) { i.ExecPostsPlugin() i.Pagination() diff --git a/internal/theme/wp/wp.go b/internal/theme/wp/wp.go index d619e5a..8677afb 100644 --- a/internal/theme/wp/wp.go +++ b/internal/theme/wp/wp.go @@ -273,7 +273,7 @@ func (h *Handle) ExecHandleFns() { } } -func (h *Handle) PreTemplate() { +func PreTemplate(h *Handle) { if h.templ == "" { h.templ = str.Join(h.theme, "/posts/index.gohtml") if h.scene == constraints.Detail { @@ -281,7 +281,7 @@ func (h *Handle) PreTemplate() { } } } -func (h *Handle) PreCodeAndStats() { +func PreCodeAndStats(h *Handle) { if h.Stats != 0 && h.Code != 0 { return }