Skip to content

Commit

Permalink
🚸 校验自定义主题、将 Theme 列表插入所有页面
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Feb 25, 2024
1 parent 8dd509a commit 07e0382
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/dashboard/controller/member_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (mp *memberPage) setting(c *gin.Context) {
c.HTML(http.StatusOK, "dashboard-"+singleton.Conf.Site.DashboardTheme+"/setting", mygin.CommonEnvironment(c, gin.H{
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Settings"}),
"Languages": model.Languages,
"Themes": model.Themes,
"DashboardThemes": model.DashboardThemes,
}))
}
1 change: 1 addition & 0 deletions pkg/mygin/mygin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H {
data["MatchedPath"] = c.MustGet("MatchedPath")
data["Version"] = singleton.Version
data["Conf"] = singleton.Conf
data["Themes"] = model.Themes
// 是否是管理页面
data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)]
// 站点标题
Expand Down
5 changes: 5 additions & 0 deletions pkg/mygin/preferred_theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (

"github.com/gin-gonic/gin"
"github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
"github.com/naiba/nezha/service/singleton"
)

func PreferredTheme(c *gin.Context) {
// 采用前端传入的主题
if theme, err := c.Cookie("preferred_theme"); err == nil {
if _, has := model.Themes[theme]; has {
// 检验自定义主题
if theme == "custom" && singleton.Conf.Site.Theme != "custom" && !utils.IsFileExists("resource/template/custom/home.html") {
return
}
c.Set(model.CtxKeyPreferredTheme, theme)
}
}
Expand Down

0 comments on commit 07e0382

Please sign in to comment.