优化一些逻辑。

This commit is contained in:
2026-08-06 17:45:06 +08:00
parent ea293f7866
commit ec1a19f469
5 changed files with 13 additions and 26 deletions
+1 -18
View File
@@ -1,7 +1,6 @@
package handlers
import (
"html/template"
"log/slog"
"math"
"net/http"
@@ -11,7 +10,6 @@ import (
"goblog/config"
"goblog/database"
"goblog/models"
"goblog/utils"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
@@ -27,21 +25,6 @@ func loadSidebarData() (categories []models.Category, tags []models.Tag, postCou
return
}
func templateFuncs() template.FuncMap {
return template.FuncMap{
"add": func(a, b int) int {
return a + b
},
"sub": func(a, b int) int {
return a - b
},
"html": func(s string) template.HTML {
return template.HTML(s)
},
"markdown": utils.RenderMarkdown,
}
}
// 首页
type IndexData struct {
Title string
@@ -79,7 +62,7 @@ func IndexView(c *gin.Context) {
Where("status = ?", "published")
userId, exists := c.Get("userID")
userId, exists = 1, true
if exists {
db = db.Or("author_id = ?", userId)
}