From 79e443c1f7a6af9a7c3224c38e1a3d97a5669483 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 17 Sep 2022 21:45:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/actions.go | 27 ++++++++++++++++++++++++--- templates/layout/sidebar.html | 4 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/route/actions.go b/route/actions.go index f500af1..551a64d 100644 --- a/route/actions.go +++ b/route/actions.go @@ -80,7 +80,7 @@ func (h *IndexHandle) parseParams() { h.where = append(h.where, []string{ "month(post_date)", month, }) - ss := fmt.Sprintf("%s年%s月", year, month) + ss := fmt.Sprintf("%s年%s月", year, strings.TrimLeft(month, "0")) h.header = fmt.Sprintf("月度归档: %s", ss) h.setTitleLR(ss, models.Options["blogname"]) } @@ -221,7 +221,9 @@ func index(c *gin.Context) { for i, v := range postIds { post, _ := PostsCache.Load(v.Id) pp := post.(*models.WpPosts) - postIds[i] = *pp + px := *pp + formatTitleAndContent(&px) + postIds[i] = px } recent, err := recentPosts() archive, err := archives() @@ -241,10 +243,29 @@ func index(c *gin.Context) { }) } +func formatTitleAndContent(post *models.WpPosts) { + if post.PostPassword != "" { + if post.PostTitle != "" { + post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle) + } + if post.PostContent != "" { + format := ` +
+

此内容受密码保护。如需查阅,请在下列字段中输入您的密码。

+

+
` + post.PostContent = fmt.Sprintf(format, post.Id, post.Id) + } + } +} + func recentPosts() (r []models.WpPosts, err error) { r, err = models.Find[models.WpPosts](models.SqlBuilder{{ "post_type", "post", - }, {"post_status", "publish"}}, "ID,post_title", "", models.SqlBuilder{{"post_date", "desc"}}, nil, 5) + }, {"post_status", "publish"}}, "ID,post_title,post_password", "", models.SqlBuilder{{"post_date", "desc"}}, nil, 5) + for i := 0; i < len(r); i++ { + formatTitleAndContent(&r[i]) + } return } diff --git a/templates/layout/sidebar.html b/templates/layout/sidebar.html index b0e15be..883ac38 100644 --- a/templates/layout/sidebar.html +++ b/templates/layout/sidebar.html @@ -15,7 +15,7 @@ @@ -31,7 +31,7 @@