未完成版基础界面

This commit is contained in:
2025-11-23 22:11:31 +08:00
parent a469da2904
commit 3b5d4b193b
7 changed files with 46 additions and 17 deletions

15
main.go
View File

@@ -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")

View File

@@ -1,4 +1,4 @@
{{ define "layout/base.html" }}
{{ define "base" }}
<!DOCTYPE html>
<html lang="zh">
<head>
@@ -7,7 +7,7 @@
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
{{ template "layout/navbar.html" . }}
{{ template "navbar" . }}
<main>
{{ block "content" . }}{{ end }}

View File

@@ -1,6 +1,6 @@
{{ define "layout/navbar.html" }}
{{ define "navbar" }}
<nav class="navbar">
<div class="logo">🔥 NanNanWu</div>
<div class="logo">🔥 MyGinSite</div>
<ul class="nav-links">
<li><a href="/">首页</a></li>
<li><a href="/about">关于我们</a></li>

View File

@@ -0,0 +1,9 @@
{{ define "about" }}
{{ template "base" . }}
{{ block "title" . }}关于我们{{ end }}
{{ block "content" . }}
<h2>关于我们</h2>
<p>这里可以写团队介绍、网站背景或使命。</p>
{{ end }}
{{ end }}

View File

@@ -0,0 +1,13 @@
{{ define "articles" }}
{{ template "base" . }}
{{ block "title" . }}文章列表{{ end }}
{{ block "content" . }}
<h2>文章列表</h2>
<ul>
{{ range .Articles }}
<li>{{ .Title }} - {{ .Date }}</li>
{{ end }}
</ul>
{{ end }}
{{ end }}

View File

@@ -0,0 +1,14 @@
{{ define "contact" }}
{{ template "base" . }}
{{ block "title" . }}联系我们{{ end }}
{{ block "content" . }}
<h2>联系我们</h2>
<form>
<label>姓名:</label><input type="text" name="name"><br>
<label>邮箱:</label><input type="email" name="email"><br>
<label>留言:</label><textarea name="message"></textarea><br>
<button type="submit">提交</button>
</form>
{{ end }}
{{ end }}

View File

@@ -1,5 +1,5 @@
{{ define "pages/index.html" }}
{{ template "layout/base.html" . }}
{{ define "index" }}
{{ template "base" . }}
{{ block "title" . }}首页{{ end }}
{{ block "content" . }}