This commit is contained in:
2023-03-10 14:11:45 +08:00
parent eff40107b2
commit d6d708bf5d
7 changed files with 27 additions and 13 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
.env
/data
/article
/article
/theme
+17 -3
View File
@@ -38,9 +38,23 @@ func Index(c *gin.Context) {
list = append(list, article)
}
}
nextPage := 0
if start+limit < total {
nextPage = p + 1
}
prevPage := 1
if p > 2 {
prevPage = p + 1
}
c.HTML(200, "index.html", gin.H{
"list": list,
"total": total,
"title": "Home",
"list": list,
"total": total,
"title": "Home",
"page": p,
"nextPage": nextPage,
"prevPage": prevPage,
})
}
+8 -9
View File
@@ -1,20 +1,14 @@
package main
import (
"embed"
"gin-article/handler"
"os"
"path/filepath"
"github.com/gin-contrib/multitemplate"
"github.com/gin-gonic/gin"
)
//go:embed tmpl/*
var tmplFs embed.FS
//go:embed statics/**/*
var staticsFs embed.FS
func loadTemplates(templatesDir string) multitemplate.Renderer {
r := multitemplate.NewRenderer()
@@ -41,8 +35,13 @@ func loadTemplates(templatesDir string) multitemplate.Renderer {
func Router() *gin.Engine {
r := gin.Default()
r.HTMLRender = loadTemplates("./tmpl")
r.Static("/statics", "statics")
themePath := os.Getenv("THEME_PATH")
if len(themePath) == 0 {
themePath = "./theme_example"
}
r.HTMLRender = loadTemplates(themePath + "/tmpl")
r.Static("/statics", themePath+"/statics")
r.GET("/", handler.Index)
r.GET("/article/:id", handler.GetArticle)