未完成版基础界面
This commit is contained in:
15
main.go
15
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")
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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>
|
||||
|
||||
9
templates/pages/about.html
Normal file
9
templates/pages/about.html
Normal file
@@ -0,0 +1,9 @@
|
||||
{{ define "about" }}
|
||||
{{ template "base" . }}
|
||||
|
||||
{{ block "title" . }}关于我们{{ end }}
|
||||
{{ block "content" . }}
|
||||
<h2>关于我们</h2>
|
||||
<p>这里可以写团队介绍、网站背景或使命。</p>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
13
templates/pages/articles.html
Normal file
13
templates/pages/articles.html
Normal 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 }}
|
||||
14
templates/pages/contact.html
Normal file
14
templates/pages/contact.html
Normal 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 }}
|
||||
@@ -1,5 +1,5 @@
|
||||
{{ define "pages/index.html" }}
|
||||
{{ template "layout/base.html" . }}
|
||||
{{ define "index" }}
|
||||
{{ template "base" . }}
|
||||
|
||||
{{ block "title" . }}首页{{ end }}
|
||||
{{ block "content" . }}
|
||||
|
||||
Reference in New Issue
Block a user