diff --git a/.gitignore b/.gitignore index 31402e9..cc0b434 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env /data -/article \ No newline at end of file +/article +/theme \ No newline at end of file diff --git a/handler/index.go b/handler/index.go index d449a1a..91234a4 100644 --- a/handler/index.go +++ b/handler/index.go @@ -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, }) } diff --git a/router.go b/router.go index 74f2433..622a00a 100644 --- a/router.go +++ b/router.go @@ -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) diff --git a/statics/css/github-markdown-light.css b/theme_example/statics/css/github-markdown-light.css similarity index 100% rename from statics/css/github-markdown-light.css rename to theme_example/statics/css/github-markdown-light.css diff --git a/tmpl/article.html b/theme_example/tmpl/article.html similarity index 100% rename from tmpl/article.html rename to theme_example/tmpl/article.html diff --git a/tmpl/index.html b/theme_example/tmpl/index.html similarity index 100% rename from tmpl/index.html rename to theme_example/tmpl/index.html diff --git a/tmpl/layouts/base.html b/theme_example/tmpl/layouts/base.html similarity index 100% rename from tmpl/layouts/base.html rename to theme_example/tmpl/layouts/base.html