qoder优化。

This commit is contained in:
2026-02-12 15:45:11 +08:00
parent bc59f616fd
commit d448e48ba3
6 changed files with 131 additions and 314 deletions

View File

@@ -44,7 +44,11 @@ func Home(c *gin.Context) {
}
var items []models.Content
db.Select("*").Limit(5).Find(&items, "type = ?", "post")
result := db.Select("*").Limit(5).Find(&items, "type = ?", "post")
if result.Error != nil {
c.String(http.StatusInternalServerError, "Database error: "+result.Error.Error())
return
}
tpl := themeManager.GetTemplate("index")
if tpl == nil {
@@ -52,9 +56,13 @@ func Home(c *gin.Context) {
return
}
c.Header("Content-Type", "text/html; charset=utf-8")
tpl.Execute(c.Writer, gin.H{
data := gin.H{
"Items": items,
"Title": "首页",
})
}
c.Header("Content-Type", "text/html; charset=utf-8")
if err := tpl.Execute(c.Writer, data); err != nil {
c.String(http.StatusInternalServerError, "Template render error: "+err.Error())
}
}