From d88dd6b853d2bc998185e96f3a13e57af7847139 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 9 Feb 2023 12:57:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/common/common.go | 16 ++++++++++++++-- .../theme/twentyseventeen/twentyseventeen.go | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/theme/common/common.go b/internal/theme/common/common.go index 9e04bf4..1039610 100644 --- a/internal/theme/common/common.go +++ b/internal/theme/common/common.go @@ -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 + } +} diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index eebd496..1d72e12 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -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)