From 3b5d4b193ba3ab2c69bc6402141f0f0293c5599d Mon Sep 17 00:00:00 2001 From: nannanwu Date: Sun, 23 Nov 2025 22:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=E7=89=88=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 15 ++++----------- templates/layout/base.html | 4 ++-- templates/layout/navbar.html | 4 ++-- templates/pages/about.html | 9 +++++++++ templates/pages/articles.html | 13 +++++++++++++ templates/pages/contact.html | 14 ++++++++++++++ templates/pages/index.html | 4 ++-- 7 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 templates/pages/about.html create mode 100644 templates/pages/articles.html create mode 100644 templates/pages/contact.html diff --git a/main.go b/main.go index 06b7351..78f0e45 100644 --- a/main.go +++ b/main.go @@ -15,20 +15,15 @@ func main() { // 路由 r.GET("/", func(c *gin.Context) { - c.HTML(200, "pages/index.html", gin.H{ - "Title": "首页", - }) + c.HTML(200, "index", gin.H{}) }) r.GET("/about", func(c *gin.Context) { - c.HTML(200, "pages/about.html", gin.H{ - "Title": "关于我们", - }) + c.HTML(200, "about", gin.H{}) }) r.GET("/articles", func(c *gin.Context) { - c.HTML(200, "pages/articles.html", gin.H{ - "Title": "文章列表", + c.HTML(200, "articles", gin.H{ "Articles": []map[string]string{ {"Title": "Gin框架入门", "Date": "2025-11-23"}, {"Title": "Go语言最佳实践", "Date": "2025-11-20"}, @@ -37,9 +32,7 @@ func main() { }) r.GET("/contact", func(c *gin.Context) { - c.HTML(200, "pages/contact.html", gin.H{ - "Title": "联系我们", - }) + c.HTML(200, "contact", gin.H{}) }) r.Run(":8080") diff --git a/templates/layout/base.html b/templates/layout/base.html index 509c25f..dae822f 100644 --- a/templates/layout/base.html +++ b/templates/layout/base.html @@ -1,4 +1,4 @@ -{{ define "layout/base.html" }} +{{ define "base" }} @@ -7,7 +7,7 @@ - {{ template "layout/navbar.html" . }} + {{ template "navbar" . }}
{{ block "content" . }}{{ end }} diff --git a/templates/layout/navbar.html b/templates/layout/navbar.html index 620bffd..e84efe0 100644 --- a/templates/layout/navbar.html +++ b/templates/layout/navbar.html @@ -1,6 +1,6 @@ -{{ define "layout/navbar.html" }} +{{ define "navbar" }}