From bd7d20160afea7f5df2e9432c05f596e8b056403 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 23 Feb 2023 20:22:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/common.go | 2 +- internal/theme/common/detail.go | 7 ------- internal/theme/common/index.go | 7 ------- internal/theme/twentyseventeen/twentyseventeen.go | 11 +++++++++-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go index e9e2073..a9c6aba 100644 --- a/internal/theme/common/common.go +++ b/internal/theme/common/common.go @@ -85,7 +85,7 @@ type HandleFn[T any] func(T) type HandlePipeFn[T any] func(HandleFn[T], T) // HandlePipe 方便把功能写在其它包里 -func HandlePipe[T any](fns []HandlePipeFn[T], initial func(T)) HandleFn[T] { +func HandlePipe[T any](initial func(T), fns ...HandlePipeFn[T]) HandleFn[T] { return slice.ReverseReduce(fns, func(next HandlePipeFn[T], f func(t T)) func(t T) { return func(t T) { next(f, t) diff --git a/internal/theme/common/detail.go b/internal/theme/common/detail.go index 918b20a..cad7b77 100644 --- a/internal/theme/common/detail.go +++ b/internal/theme/common/detail.go @@ -17,19 +17,12 @@ type DetailHandle struct { CommentRender plugins.CommentHtml Comments []models.Comments Post models.Posts - Pipes []HandlePipeFn[*DetailHandle] } func NewDetailHandle(handle *Handle) *DetailHandle { return &DetailHandle{Handle: handle} } -func (d *DetailHandle) Pipe(calls ...HandlePipeFn[*DetailHandle]) { - HandlePipe[*DetailHandle](append(calls, d.Pipes...), func(d *DetailHandle) { - d.Render() - })(d) -} - func (d *DetailHandle) BuildDetailData() (err error) { d.GinH["title"] = wpconfig.GetOption("blogname") err = d.CheckAndGetPost() diff --git a/internal/theme/common/index.go b/internal/theme/common/index.go index 13c8aba..1c03d2e 100644 --- a/internal/theme/common/index.go +++ b/internal/theme/common/index.go @@ -22,19 +22,12 @@ type IndexHandle struct { PageEle pagination.Elements TotalRows int PostsPlugins map[string]Plugin[models.Posts, *Handle] - Pipes []HandlePipeFn[*IndexHandle] } func NewIndexHandle(handle *Handle) *IndexHandle { return &IndexHandle{Handle: handle} } -func (i *IndexHandle) Pipe(calls ...HandlePipeFn[*IndexHandle]) { - HandlePipe[*IndexHandle](append(calls, i.Pipes...), func(i *IndexHandle) { - i.Render() - })(i) -} - func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) { i.Param = parm switch i.Scene { diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index e837b5b..cedad8d 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -28,16 +28,23 @@ var paginate = func() plugins.PageEle { return p }() +var detailPipe = common.HandlePipe(func(d *common.DetailHandle) { + d.Render() +}, detail) +var indexPipe = common.HandlePipe(func(i *common.IndexHandle) { + i.Render() +}, index) + func Hook(h *common.Handle) { h.WidgetAreaData() h.GetPassword() h.HandleFns = append(h.HandleFns, calClass) h.GinH["HeaderImage"] = getHeaderImage(h.C) if h.Scene == constraints.Detail { - common.NewDetailHandle(h).Pipe(detail) + detailPipe(common.NewDetailHandle(h)) return } - common.NewIndexHandle(h).Pipe(index) + indexPipe(common.NewIndexHandle(h)) } var pluginFns = func() map[string]common.Plugin[models.Posts, *common.Handle] {