小优化
This commit is contained in:
parent
febaab279d
commit
d88dd6b853
|
@ -1,6 +1,7 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||
|
@ -29,11 +30,11 @@ func PluginFn[T any](a []Plugin[T], h Handle, fn Fn[T]) Fn[T] {
|
|||
}
|
||||
|
||||
var plugin = []Plugin[models.Posts]{
|
||||
PasswordProject, Digest,
|
||||
PasswordProject,
|
||||
}
|
||||
|
||||
func Plugins() []Plugin[models.Posts] {
|
||||
return plugin
|
||||
return slice.Copy(plugin)
|
||||
}
|
||||
|
||||
func Default[T any](t T) T {
|
||||
|
@ -61,3 +62,14 @@ func Digest(next Fn[models.Posts], h Handle, post models.Posts) models.Posts {
|
|||
}
|
||||
return next(post)
|
||||
}
|
||||
|
||||
func Digests(ctx context.Context) Fn[models.Posts] {
|
||||
return func(post models.Posts) models.Posts {
|
||||
if post.PostExcerpt != "" {
|
||||
plugins.PostExcerpt(&post)
|
||||
} else {
|
||||
plugins.Digest(ctx, &post, config.GetConfig().DigestWordCount)
|
||||
}
|
||||
return post
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,12 @@ func Hook(h2 common.Handle) {
|
|||
h.index()
|
||||
}
|
||||
|
||||
var plugin = slice.Copy(common.Plugins())
|
||||
var plugin = common.Plugins()
|
||||
|
||||
func (h handle) index() {
|
||||
if h.Stats != plugins.Empty404 {
|
||||
posts := h.GinH["posts"].([]models.Posts)
|
||||
posts = slice.Map(posts, common.PluginFn[models.Posts](plugin, h.Handle, common.Default[models.Posts]))
|
||||
posts = slice.Map(posts, common.PluginFn[models.Posts](plugin, h.Handle, common.Digests(h.C)))
|
||||
p, ok := h.GinH["pagination"]
|
||||
if ok {
|
||||
pp, ok := p.(pagination.ParsePagination)
|
||||
|
|
Loading…
Reference in New Issue
Block a user