删除部分多余内容。

This commit is contained in:
2026-08-20 22:15:21 +08:00
parent 6e88700f96
commit 052803679a
2 changed files with 38 additions and 27 deletions
+24 -13
View File
@@ -154,15 +154,11 @@ type PostDetailData struct {
Description string
Post models.Post
Pages []models.Page
Comments []models.Comment
CommentCount int64
Year int
PrevPost *models.Post // 上一篇
NextPost *models.Post // 下一篇
// 评论展示设置与分页
ShowComments bool
CommentPage int
CommentTotalPages int
ShowComments bool
CommentCount int64
// Sidebar 数据
Categories []models.Category
Tags []models.Tag
@@ -206,6 +202,19 @@ func PostView(c *gin.Context) {
pages := loadPublishedPages()
showComments := true
if v, optErr := models.GetOptionValue(database.DB, models.OptionShowComments, 0); optErr == nil {
showComments = v != "0"
}
// 统计评论数
if showComments {
var commentCount int64
database.DB.Model(&models.Comment{}).Where("post_id = ? AND status = ?", post.ID, "approved").Count(&commentCount)
}
var commentCount int64
database.DB.Model(&models.Comment{}).Where("post_id = ? AND status = ?", post.ID, "approved").Count(&commentCount)
// 获取上一篇(发布时间更早的文章)
var prevPost models.Post
prevErr := database.DB.Where("status = ? AND published_at < ?", "published", post.PublishedAt).
@@ -220,13 +229,15 @@ func PostView(c *gin.Context) {
categories, tags, postCount, categoryCount, tagCount := loadSidebarData()
data := PostDetailData{
Title: post.Title,
SiteName: siteName,
SiteDesc: siteDesc,
Description: post.Summary,
Post: post,
Pages: pages,
Year: time.Now().Year(),
Title: post.Title,
SiteName: siteName,
SiteDesc: siteDesc,
Description: post.Summary,
Post: post,
Pages: pages,
Year: time.Now().Year(),
ShowComments: showComments,
CommentCount: commentCount,
// Sidebar 数据
Categories: categories,
Tags: tags,