From 9dbbfac551fbccd62771c317c7629cd5d9cb9454 Mon Sep 17 00:00:00 2001 From: naiba Date: Sat, 19 Dec 2020 10:57:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(theme):=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++++++++++ cmd/agent/main.go | 2 +- cmd/dashboard/controller/common_page.go | 3 ++- cmd/dashboard/controller/controller.go | 7 +++++++ cmd/dashboard/controller/member_api.go | 8 +++++--- model/config.go | 1 + resource/template/dashboard/setting.html | 4 ++++ resource/template/theme-default/home.html | 5 +++++ resource/template/theme-hotaru/home.html | 5 +++++ 9 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4b304b9..f0ec85e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,24 @@ sudo ./nezha.sh ``` +## 主题自定义 + +- 默认主题更改进度条颜色示例 + + ``` + .ui.green.progress> .bar { + background-color: pink !important; + } + ``` + +- hotaru 主题更改背景图片示例 + + ``` + .hotaru-cover { + background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center; + } + ``` + ## 常见问题 ### 启用 HTTPS diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 01e72bb..f96e4cf 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -25,7 +25,7 @@ var ( server string clientSecret string debug bool - version string + version = "v9.9.9" rootCmd = &cobra.Command{ Use: "nezha-agent", diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index 9b22ac4..f391c5a 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -29,7 +29,8 @@ func (cp *commonPage) home(c *gin.Context) { dao.ServerLock.RLock() defer dao.ServerLock.RUnlock() data := gin.H{ - "Servers": dao.ServerList, + "Servers": dao.ServerList, + "CustomCSS": dao.Conf.Site.CustomCSS, } u, ok := c.Get(model.CtxKeyAuthorizedUser) if ok { diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index 95485b9..b589c89 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -3,6 +3,7 @@ package controller import ( "fmt" "html/template" + "strings" "time" "code.cloudfoundry.org/bytefmt" @@ -24,6 +25,9 @@ func ServeWeb(port uint) { "tf": func(t time.Time) string { return t.Format("2006年1月2号") }, + "css": func(s string) template.CSS { + return template.CSS(s) + }, "stf": func(s uint64) string { return time.Unix(int64(s), 0).Format("2006年1月2号 15:04") }, @@ -33,6 +37,9 @@ func ServeWeb(port uint) { "bf": func(b uint64) string { return bytefmt.ByteSize(b) }, + "ts": func(s string) string { + return strings.TrimSpace(s) + }, }) r.Static("/static", "resource/static") r.LoadHTMLGlob("resource/template/**/*") diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 9385a5c..b5d5a3b 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -127,9 +127,10 @@ func (ma *memberAPI) logout(c *gin.Context) { } type settingForm struct { - Title string - Admin string - Theme string + Title string + Admin string + Theme string + CustomCSS string } func (ma *memberAPI) updateSetting(c *gin.Context) { @@ -143,6 +144,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) { } dao.Conf.Site.Brand = sf.Title dao.Conf.Site.Theme = sf.Theme + dao.Conf.Site.CustomCSS = sf.CustomCSS dao.Conf.GitHub.Admin = sf.Admin if err := dao.Conf.Save(); err != nil { c.JSON(http.StatusOK, model.Response{ diff --git a/model/config.go b/model/config.go index edf8206..70d2b7c 100644 --- a/model/config.go +++ b/model/config.go @@ -17,6 +17,7 @@ type Config struct { Brand string // 站点名称 CookieName string // 浏览器 Cookie 名称 Theme string + CustomCSS string } GitHub struct { Admin string // 管理员ID列表 diff --git a/resource/template/dashboard/setting.html b/resource/template/dashboard/setting.html index 8863f08..5ac37c1 100644 --- a/resource/template/dashboard/setting.html +++ b/resource/template/dashboard/setting.html @@ -18,6 +18,10 @@ +
+ + +
diff --git a/resource/template/theme-default/home.html b/resource/template/theme-default/home.html index cb0f972..21e389d 100644 --- a/resource/template/theme-default/home.html +++ b/resource/template/theme-default/home.html @@ -1,5 +1,10 @@ {{define "theme-default/home"}} {{template "common/header" .}} +{{if ts .CustomCSS}} + +{{end}} {{template "common/menu" .}}
diff --git a/resource/template/theme-hotaru/home.html b/resource/template/theme-hotaru/home.html index f2ad7e4..0c39c6b 100644 --- a/resource/template/theme-hotaru/home.html +++ b/resource/template/theme-hotaru/home.html @@ -19,6 +19,11 @@ + {{if ts .CustomCSS}} + + {{end}}