add admin router

This commit is contained in:
张超
2025-06-18 18:34:08 +08:00
parent 67c85327ee
commit 4c9f6c140f
4 changed files with 32 additions and 86 deletions

View File

@@ -1,6 +1,7 @@
package controllers
import (
"html/template"
"net/http"
"go_blog/config"
@@ -31,12 +32,14 @@ func ListThemes(c *gin.Context) {
}
// 渲染管理页面模板
tpl := themeManager.GetTemplate("admin/themes") // 对应 templates/admin/themes.tmpl
if tpl == nil {
c.String(http.StatusInternalServerError, "模板 'admin/themes' 未找到")
// 直接加载 web/admin/themes.tmpl 文件(路径相对于项目根目录)
const themesTemplatePath = "web/admin/themes.tmpl" // 定义模板路径常量
tpl, err := template.ParseFiles(themesTemplatePath)
if err != nil {
c.String(http.StatusInternalServerError, "模板加载失败: "+err.Error())
return
}
c.Header("Content-Type", "text/html; charset=utf-8")
err = tpl.Execute(c.Writer, gin.H{
"CurrentTheme": themeManager.CurrentTheme(),