feat: 补上站点名称和描述的坑

This commit is contained in:
Akizon77 committed 2025-06-18 23:54:01 +08:00
1 parent dbf6e24d68
commit 12ad38fc78
1 file changed
+13 -3
+13 -3
View File
@@ -4,6 +4,7 @@ import (
"embed"
"errors"
"fmt"
"html"
"io"
"io/fs"
"log"
@@ -47,13 +48,22 @@ func initIndex() {
RawIndexFile = string(index)
}
func UpdateIndex(cfg models.Config) {
var titleReplacement string
if cfg.Sitename == "Komari" {
titleReplacement = "<title>Komari Monitor</title>"
} else {
titleReplacement = fmt.Sprintf("<title>%s - Komari Monitor</title>", html.EscapeString(cfg.Sitename))
}
replaceMap := map[string]string{
"</head>": cfg.CustomHead + "</head>",
"</body>": cfg.CustomBody + "</body>",
"<title>Komari Monitor</title>": titleReplacement,
"A simple server monitor tool.": cfg.Description,
"</head>": cfg.CustomHead + "</head>",
"</body>": cfg.CustomBody + "</body>",
}
updated := RawIndexFile
for k, v := range replaceMap {
updated = strings.Replace(updated, k, v, 1)
updated = strings.Replace(updated, k, v, -1)
}
IndexFile = updated
}