优化一些逻辑。
This commit is contained in:
+1
-18
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user