完善
This commit is contained in:
parent
bfd4e4ac4d
commit
b1e824b27d
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue
Block a user