Skip to content

Commit f6cb075

Browse files
xrgzsSuyunmeng
authored andcommitted
fix(static): support logo replacement (#834 Close #754)
1 parent 8ed4fcc commit f6cb075

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

internal/conf/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
AllowMounted = "allow_mounted"
1818
RobotsTxt = "robots_txt"
1919

20-
Logo = "logo"
20+
Logo = "logo" // multi-lines text, L1: light, EOL: dark
2121
Favicon = "favicon"
2222
MainColor = "main_color"
2323

server/static/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type SiteConfig struct {
1515
func getSiteConfig() SiteConfig {
1616
siteConfig := SiteConfig{
1717
BasePath: conf.URL.Path,
18-
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", strings.TrimPrefix(conf.WebVersion, "v"),),
18+
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", strings.TrimPrefix(conf.WebVersion, "v")),
1919
}
2020
if siteConfig.BasePath != "" {
2121
siteConfig.BasePath = utils.FixAndCleanPath(siteConfig.BasePath)

server/static/static.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ func replaceStrings(content string, replacements map[string]string) string {
4141
return content
4242
}
4343

44-
func initIndex() {
44+
func initIndex(siteConfig SiteConfig) {
4545
utils.Log.Debug("Initializing index.html...")
46-
siteConfig := getSiteConfig()
4746
// dist_dir is empty and cdn is not empty add web_version is empty or beta or dev
4847
if conf.Conf.DistDir == "" && conf.Conf.Cdn != "" && (conf.WebVersion == "" || conf.WebVersion == "beta" || conf.WebVersion == "dev") {
4948
utils.Log.Infof("Fetching index.html from CDN: %s/index.html...", conf.Conf.Cdn)
@@ -89,13 +88,15 @@ func initIndex() {
8988
func UpdateIndex() {
9089
utils.Log.Debug("Updating index.html with settings...")
9190
favicon := setting.GetStr(conf.Favicon)
91+
logo := strings.Split(setting.GetStr(conf.Logo), "\n")[0]
9292
title := setting.GetStr(conf.SiteTitle)
9393
customizeHead := setting.GetStr(conf.CustomizeHead)
9494
customizeBody := setting.GetStr(conf.CustomizeBody)
9595
mainColor := setting.GetStr(conf.MainColor)
9696
utils.Log.Debug("Applying replacements for default pages...")
9797
replaceMap1 := map[string]string{
9898
"https://cdn.oplist.org/gh/OpenListTeam/Logo@main/logo.svg": favicon,
99+
"https://cdn.oplist.org/gh/OpenListTeam/Logo@main/logo.png": logo,
99100
"Loading...": title,
100101
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
101102
}
@@ -111,8 +112,9 @@ func UpdateIndex() {
111112

112113
func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) {
113114
utils.Log.Debug("Setting up static routes...")
115+
siteConfig := getSiteConfig()
114116
initStatic()
115-
initIndex()
117+
initIndex(siteConfig)
116118
folders := []string{"assets", "images", "streamer", "static"}
117119
if conf.Conf.Cdn == "" {
118120
utils.Log.Debug("Setting up static file serving...")
@@ -136,7 +138,7 @@ func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) {
136138
for _, folder := range folders {
137139
r.GET(fmt.Sprintf("/%s/*filepath", folder), func(c *gin.Context) {
138140
filepath := c.Param("filepath")
139-
c.Redirect(http.StatusFound, fmt.Sprintf("%s/%s%s", conf.Conf.Cdn, folder, filepath))
141+
c.Redirect(http.StatusFound, fmt.Sprintf("%s/%s%s", siteConfig.Cdn, folder, filepath))
140142
})
141143
}
142144
}

0 commit comments

Comments
 (0)