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 @@