Skip to content

Commit

Permalink
feat: enhance template configuration and update README for translatio…
Browse files Browse the repository at this point in the history
…n status
  • Loading branch information
naiba committed Dec 10, 2024
1 parent 8f8a30c commit 06738d5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

### Translation

<a href="https://hosted.weblate.org/engage/nezha/">
<img src="https://hosted.weblate.org/widget/nezha/multi-blue.svg" alt="Translation status" />
</a>

Is Nezha not in your language, or the translation is incorrect or incomplete? Get involved in the translations on [Hosted Weblate](https://hosted.weblate.org/engage/nezha/).

## Screenshots
Expand All @@ -35,6 +39,8 @@ Is Nezha not in your language, or the translation is incorrect or incomplete? Ge
| ![user](.github/user-frontend.20241128.png) | ![admin](.github/admin-frontend.20241128.png) |
| [hamster1963/nezha-dash](https://github.com/hamster1963/nezha-dash) | [nezhahq/admin-frontend](https://github.com/nezhahq/admin-frontend) |

add your theme to [service/singleton/frontend-templates.yaml](service/singleton/frontend-templates.yaml)

## Contributors

<!--GAMFC_DELIMITER--><a href="https://github.com/naiba" title="naiba"><img src="https://avatars.githubusercontent.com/u/29243953?v=4" width="50;" alt="naiba"/></a>
Expand Down
4 changes: 2 additions & 2 deletions cmd/dashboard/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
}
if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
localFilePath := path.Join("admin-dist", stripPath)
localFilePath := path.Join(singleton.Conf.AdminTemplate, stripPath)
if checkLocalFileOrFs(c, frontendDist, localFilePath) {
return
}
if !checkLocalFileOrFs(c, frontendDist, "admin-dist/index.html") {
if !checkLocalFileOrFs(c, frontendDist, singleton.Conf.AdminTemplate+"/index.html") {
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
}
return
Expand Down
4 changes: 3 additions & 1 deletion cmd/dashboard/controller/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ func updateConfig(c *gin.Context) (any, error) {
}
var userTemplateValid bool
for _, v := range singleton.FrontendTemplates {
if v.Path == sf.UserTemplate && sf.UserTemplate != "admin-dist" {
if !userTemplateValid && v.Path == sf.UserTemplate && !v.IsAdmin {
userTemplateValid = true
}
if userTemplateValid {
break
}
}
Expand Down
13 changes: 11 additions & 2 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
Language string `mapstructure:"language" json:"language"` // 系统语言,默认 zh_CN
SiteName string `mapstructure:"site_name" json:"site_name"`
UserTemplate string `mapstructure:"user_template" json:"user_template,omitempty"`
AdminTemplate string `mapstructure:"admin_template" json:"admin_template,omitempty"`
JWTSecretKey string `mapstructure:"jwt_secret_key" json:"jwt_secret_key,omitempty"`
AgentSecretKey string `mapstructure:"agent_secret_key" json:"agent_secret_key,omitempty"`
ListenPort uint `mapstructure:"listen_port" json:"listen_port,omitempty"`
Expand Down Expand Up @@ -88,16 +89,24 @@ func (c *Config) Read(path string, frontendTemplates []FrontendTemplate) error {
if c.Location == "" {
c.Location = "Asia/Shanghai"
}
var userTemplateValid bool
var userTemplateValid, adminTemplateValid bool
for _, v := range frontendTemplates {
if v.Path == c.UserTemplate && c.UserTemplate != "admin-dist" {
if !userTemplateValid && v.Path == c.UserTemplate && !v.IsAdmin {
userTemplateValid = true
}
if !adminTemplateValid && v.Path == c.AdminTemplate && v.IsAdmin {
adminTemplateValid = true
}
if userTemplateValid && adminTemplateValid {
break
}
}
if c.UserTemplate == "" || !userTemplateValid {
c.UserTemplate = "user-dist"
}
if c.AdminTemplate == "" || !adminTemplateValid {
c.AdminTemplate = "admin-dist"
}
if c.AvgPingCount == 0 {
c.AvgPingCount = 2
}
Expand Down
4 changes: 2 additions & 2 deletions model/setting_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type FrontendTemplate struct {
Name string `json:"name,omitempty"`
Repository string `json:"repository,omitempty"`
Author string `json:"author,omitempty"`
Community bool `json:"community,omitempty"`
Version string `json:"version,omitempty"`
IsAdmin string `json:"is_admin,omitempty"`
IsAdmin bool `json:"is_admin,omitempty"`
IsOfficial bool `json:"is_official,omitempty"`
}

type SettingResponse struct {
Expand Down
7 changes: 4 additions & 3 deletions service/singleton/frontend-templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
name: "OfficialAdmin"
repository: "https://github.com/nezhahq/admin-frontend"
author: "nezhahq"
version: "v1.1.1"
version: "v1.1.3"
isadmin: true
isofficial: true
- path: "user-dist"
name: "Official"
repository: "https://github.com/hamster1963/nezha-dash-v1"
author: "hamster1963"
version: "v1.2.5"
isofficial: true
- path: "nazhua-dist"
name: "Nazhua"
repository: "https://github.com/hi2shark/nazhua"
author: "hi2hi"
version: "v0.4.10"
community: true
version: "v0.4.13"

0 comments on commit 06738d5

Please sign in to comment.