Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(cdn): fix cdn replace

kumfo70ddccc27e64
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index b484dc4f..a7d69ebc 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -517,6 +517,9 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI
})
if prefix != "" {
+ if prefix[len(prefix)-1:] == "/" {
+ prefix = strings.TrimSuffix(prefix, "/")
+ }
cssPath = prefix + tc.cssPath
for i, path := range tc.scriptPath {
scriptPath[i] = prefix + path
diff --git a/internal/router/ui.go b/internal/router/ui.go
index b553fb47..1d68384e 100644
--- a/internal/router/ui.go
+++ b/internal/router/ui.go
@@ -148,6 +148,9 @@ func (a *UIRouter) Register(r *gin.Engine, baseURLPath string) {
return nil
})
if cdnPrefix != "" {
+ if cdnPrefix[len(cdnPrefix)-1:] == "/" {
+ cdnPrefix = strings.TrimSuffix(cdnPrefix, "/")
+ }
c.String(http.StatusOK, strings.ReplaceAll(string(file), "/static", cdnPrefix+"/static"))
return
}