update
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
.env
|
.env
|
||||||
/data
|
/data
|
||||||
/article
|
/article
|
||||||
|
/theme
|
||||||
@@ -38,9 +38,23 @@ func Index(c *gin.Context) {
|
|||||||
list = append(list, article)
|
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{
|
c.HTML(200, "index.html", gin.H{
|
||||||
"list": list,
|
"list": list,
|
||||||
"total": total,
|
"total": total,
|
||||||
"title": "Home",
|
"title": "Home",
|
||||||
|
"page": p,
|
||||||
|
"nextPage": nextPage,
|
||||||
|
"prevPage": prevPage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
|
||||||
"gin-article/handler"
|
"gin-article/handler"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/gin-contrib/multitemplate"
|
"github.com/gin-contrib/multitemplate"
|
||||||
"github.com/gin-gonic/gin"
|
"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 {
|
func loadTemplates(templatesDir string) multitemplate.Renderer {
|
||||||
r := multitemplate.NewRenderer()
|
r := multitemplate.NewRenderer()
|
||||||
|
|
||||||
@@ -41,8 +35,13 @@ func loadTemplates(templatesDir string) multitemplate.Renderer {
|
|||||||
func Router() *gin.Engine {
|
func Router() *gin.Engine {
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
r.HTMLRender = loadTemplates("./tmpl")
|
themePath := os.Getenv("THEME_PATH")
|
||||||
r.Static("/statics", "statics")
|
if len(themePath) == 0 {
|
||||||
|
themePath = "./theme_example"
|
||||||
|
}
|
||||||
|
|
||||||
|
r.HTMLRender = loadTemplates(themePath + "/tmpl")
|
||||||
|
r.Static("/statics", themePath+"/statics")
|
||||||
|
|
||||||
r.GET("/", handler.Index)
|
r.GET("/", handler.Index)
|
||||||
r.GET("/article/:id", handler.GetArticle)
|
r.GET("/article/:id", handler.GetArticle)
|
||||||
|
|||||||
Reference in New Issue
Block a user