From 07e0382598400b1a6e33bc0e305f9d51b3045bb8 Mon Sep 17 00:00:00 2001 From: naiba Date: Sun, 25 Feb 2024 14:15:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20=E6=A0=A1=E9=AA=8C=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=B8=BB=E9=A2=98=E3=80=81=E5=B0=86=20Theme?= =?UTF-8?q?=20=E5=88=97=E8=A1=A8=E6=8F=92=E5=85=A5=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/member_page.go | 1 - pkg/mygin/mygin.go | 1 + pkg/mygin/preferred_theme.go | 5 +++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/dashboard/controller/member_page.go b/cmd/dashboard/controller/member_page.go index 66c734a..d6e3b5c 100644 --- a/cmd/dashboard/controller/member_page.go +++ b/cmd/dashboard/controller/member_page.go @@ -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, })) } diff --git a/pkg/mygin/mygin.go b/pkg/mygin/mygin.go index 47593cb..604ffd3 100644 --- a/pkg/mygin/mygin.go +++ b/pkg/mygin/mygin.go @@ -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)] // 站点标题 diff --git a/pkg/mygin/preferred_theme.go b/pkg/mygin/preferred_theme.go index be10a61..e02afcc 100644 --- a/pkg/mygin/preferred_theme.go +++ b/pkg/mygin/preferred_theme.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "github.com/naiba/nezha/model" + "github.com/naiba/nezha/pkg/utils" "github.com/naiba/nezha/service/singleton" ) @@ -12,6 +13,10 @@ 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) } }