From 179e1e14e270284b6fd7b94e27c24d89d450a68a Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 10 Mar 2023 18:33:09 +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/wp/recentposts.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/theme/wp/recentposts.go b/internal/theme/wp/recentposts.go index d645c16..4274938 100644 --- a/internal/theme/wp/recentposts.go +++ b/internal/theme/wp/recentposts.go @@ -23,10 +23,12 @@ var recentPostsArgs = map[string]string{ "{$after_sidebar}": "", "{$nav}": "", "{$navCloser}": "", + "{$title}": "", } var recentPostsTemplate = `{$before_widget} {$nav} +{$title} @@ -44,13 +46,14 @@ func RecentPosts(h *Handle) string { args := GetComponentsArgs(h, components.RecentPostsArgs, recentPostsArgs) args = maps.Merge(recentPostsArgs, args) conf := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recentConf, int64(2)) + args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") { args["{$nav}"] = fmt.Sprintf(`" } currentPostId := uint64(0) if h.Scene() == constraints.Detail { - currentPostId = h.Detail.Post.Id + currentPostId = str.ToInteger(h.C.Param("id"), uint64(0)) } posts := slice.Map(cache.RecentPosts(h.C, int(conf["number"].(int64))), func(t models.Posts) string { t = ProjectTitle(t) @@ -62,10 +65,10 @@ func RecentPosts(h *Handle) string { if currentPostId == t.Id { ariaCurrent = ` aria-current="page"` } - return fmt.Sprintf(`
  • - %s - %s -
  • `, str.Join("/p/", number.ToString(t.Id)), ariaCurrent, t.PostTitle, date) + return fmt.Sprintf(`
  • + %s + %s +
  • `, str.Join("/p/", number.ToString(t.Id)), ariaCurrent, t.PostTitle, date) }) s := strings.ReplaceAll(recentPostsTemplate, "{$li}", strings.Join(posts, "\n")) return str.Replace(s, args)