From b1e824b27d25aa9a11872ab3bb144e189a0ebd92 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 12 Feb 2023 19:19:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/common.go | 10 +++++----- internal/theme/common/indexparams.go | 2 +- internal/theme/common/listpostplugins.go | 8 ++++---- internal/theme/twentyseventeen/twentyseventeen.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go index a616eff..73f332b 100644 --- a/internal/theme/common/common.go +++ b/internal/theme/common/common.go @@ -45,17 +45,17 @@ func (h *Handle) GetPassword() { } } -func (i *IndexHandle) ExecListPagePlugin(m map[string]Plugin[models.Posts], calls ...func(*models.Posts)) { +func (i *IndexHandle) ExecListPagePlugin(m map[string]Plugin[models.Posts, *Handle], calls ...func(*models.Posts)) { pluginConf := config.GetConfig().ListPagePlugins plugin := GetListPostPlugins(pluginConf, m) - i.GinH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts](plugin, i.Handle, Defaults(calls...))) + i.GinH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts, *Handle](plugin, i.Handle, Defaults(calls...))) } -func ListPostPlugins() map[string]Plugin[models.Posts] { +func ListPostPlugins() map[string]Plugin[models.Posts, *Handle] { return maps.Copy(pluginFns) } @@ -79,8 +79,8 @@ func ProjectTitle(t models.Posts) models.Posts { return t } -func GetListPostPlugins(name []string, m map[string]Plugin[models.Posts]) []Plugin[models.Posts] { - return slice.FilterAndMap(name, func(t string) (Plugin[models.Posts], bool) { +func GetListPostPlugins(name []string, m map[string]Plugin[models.Posts, *Handle]) []Plugin[models.Posts, *Handle] { + return slice.FilterAndMap(name, func(t string) (Plugin[models.Posts, *Handle], bool) { v, ok := m[t] if ok { return v, true diff --git a/internal/theme/common/indexparams.go b/internal/theme/common/indexparams.go index b174f5a..bb10aa1 100644 --- a/internal/theme/common/indexparams.go +++ b/internal/theme/common/indexparams.go @@ -61,7 +61,7 @@ type IndexHandle struct { Posts []models.Posts PageEle pagination.Elements TotalRows int - PostsPlugins map[string]Plugin[models.Posts] + PostsPlugins map[string]Plugin[models.Posts, *Handle] } func NewIndexHandle(handle *Handle) *IndexHandle { diff --git a/internal/theme/common/listpostplugins.go b/internal/theme/common/listpostplugins.go index 2a961df..d2f7de0 100644 --- a/internal/theme/common/listpostplugins.go +++ b/internal/theme/common/listpostplugins.go @@ -8,17 +8,17 @@ import ( ) type Fn[T any] func(T) T -type Plugin[T any] func(initialFn Fn[T], h *Handle, t T) T +type Plugin[T, H any] func(initialFn Fn[T], h H, t T) T -func PluginFn[T any](a []Plugin[T], h *Handle, fn Fn[T]) Fn[T] { - return slice.ReverseReduce(a, func(next Plugin[T], fn Fn[T]) Fn[T] { +func PluginFn[T, H any](a []Plugin[T, H], h H, fn Fn[T]) Fn[T] { + return slice.ReverseReduce(a, func(next Plugin[T, H], fn Fn[T]) Fn[T] { return func(t T) T { return next(fn, h, t) } }, fn) } -var pluginFns = map[string]Plugin[models.Posts]{ +var pluginFns = map[string]Plugin[models.Posts, *Handle]{ "passwordProject": PasswordProject, "digest": Digest, } diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index 291b229..d014a3e 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -65,8 +65,8 @@ func Hook(h *common.Handle) { newIndexHandle(common.NewIndexHandle(h)).Index() } -var pluginFns = func() map[string]common.Plugin[models.Posts] { - return maps.Merge(common.ListPostPlugins(), map[string]common.Plugin[models.Posts]{ +var pluginFns = func() map[string]common.Plugin[models.Posts, *common.Handle] { + return maps.Merge(common.ListPostPlugins(), map[string]common.Plugin[models.Posts, *common.Handle]{ "twentyseventeen_postThumbnail": postThumbnail, }) }()