From e974da8adb33c1fa9a38fa37f2c6ea18973f32b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=B6=85?= <17805310388@139.com> Date: Fri, 2 Aug 2024 21:47:22 +0800 Subject: [PATCH] add post list --- main.go | 2 +- templates/index.tmpl | 115 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index e302dc8..d0cee99 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func main() { func registerRoutes(r *gin.Engine) { var items []models.Content - models.DB.Select("*").Find(&items) + models.DB.Select("*").Limit(5).Find(&items, "type = ?", "post") r.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.tmpl", gin.H{ "Items": items, diff --git a/templates/index.tmpl b/templates/index.tmpl index dda0c2e..70d3806 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -4,20 +4,115 @@ My Blog + -

Welcome to my blog!

-

This is a simple blog written using Go and Gin framework.

- Go语言入门
- Gin框架入门
- Web开发基础
- - + + +