From 1f7e51858b98335e0a0c1f404c8b429c4f8ac300 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 7 Mar 2023 17:13:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=90=8E=E5=8F=B0=E8=BF=91?= =?UTF-8?q?=E6=9C=9F=E8=AF=84=E8=AE=BA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pkg/cache/comments.go | 6 ++--- .../theme/twentyfifteen/layout/sidebar.gohtml | 16 ++++--------- .../twentyseventeen/layout/sidebar.gohtml | 12 +--------- .../components/widget/recent-comments.gohtml | 14 +++++++++++ internal/theme/wp/widgetareadata.go | 23 ++++++++++++------- 5 files changed, 36 insertions(+), 35 deletions(-) create mode 100644 internal/theme/wp/components/widget/recent-comments.gohtml diff --git a/internal/pkg/cache/comments.go b/internal/pkg/cache/comments.go index 4c4b922..a1572fe 100644 --- a/internal/pkg/cache/comments.go +++ b/internal/pkg/cache/comments.go @@ -3,16 +3,14 @@ package cache import ( "context" "github.com/fthvgb1/wp-go/cache" + "github.com/fthvgb1/wp-go/helper/number" "github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/models" "time" ) func RecentComments(ctx context.Context, n int) (r []models.Comments) { - nn := n - if nn <= 5 { - nn = 10 - } + nn := number.Max(n, 10) r, err := recentCommentsCaches.GetCache(ctx, time.Second, ctx, nn) if len(r) > n { r = r[0:n] diff --git a/internal/theme/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml index 367b315..67b5a6c 100644 --- a/internal/theme/twentyfifteen/layout/sidebar.gohtml +++ b/internal/theme/twentyfifteen/layout/sidebar.gohtml @@ -1,6 +1,9 @@ {{define "layout/sidebar" }}