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
+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)