You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ku...@apache.org on 2024/07/19 09:56:41 UTC
(incubator-answer) branch fix/1.3.6/cdn created (now 2a030c23)
This is an automated email from the ASF dual-hosted git repository.
kumfo pushed a change to branch fix/1.3.6/cdn
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
at 2a030c23 fix(cdn): fix cdn path render
This branch includes the following new commits:
new 2a030c23 fix(cdn): fix cdn path render
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-answer) 01/01: fix(cdn): fix cdn path render
Posted by ku...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kumfo pushed a commit to branch fix/1.3.6/cdn
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 2a030c23cd54f87134e38c44bccbb4d31794fe66
Author: kumfo <ku...@sifou.com>
AuthorDate: Fri Jul 19 17:56:32 2024 +0800
fix(cdn): fix cdn path render
---
internal/controller/template_controller.go | 35 +++++++++++++++++++++---------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index e76a96c0..b484dc4f 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -70,12 +70,6 @@ func NewTemplateController(
}
}
func GetStyle() (script []string, css string) {
- prefix := ""
- _ = plugin.CallCDN(func(fn plugin.CDN) error {
- prefix = fn.GetStaticPrefix()
- return nil
- })
-
file, err := ui.Build.ReadFile("build/index.html")
if err != nil {
return
@@ -84,14 +78,14 @@ func GetStyle() (script []string, css string) {
scriptData := scriptRegexp.FindAllStringSubmatch(string(file), -1)
for _, s := range scriptData {
if len(s) == 2 {
- script = append(script, prefix+s[1])
+ script = append(script, s[1])
}
}
cssRegexp := regexp.MustCompile(`<link href="(.*)" rel="stylesheet">`)
cssListData := cssRegexp.FindStringSubmatch(string(file))
if len(cssListData) == 2 {
- css = prefix + cssListData[1]
+ css = cssListData[1]
}
return
}
@@ -511,13 +505,34 @@ func (tc *TemplateController) Page404(ctx *gin.Context) {
}
func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteInfo *schema.TemplateSiteInfoResp, data gin.H) {
+ var (
+ prefix = ""
+ cssPath = ""
+ scriptPath = make([]string, len(tc.scriptPath))
+ )
+
+ _ = plugin.CallCDN(func(fn plugin.CDN) error {
+ prefix = fn.GetStaticPrefix()
+ return nil
+ })
+
+ if prefix != "" {
+ cssPath = prefix + tc.cssPath
+ for i, path := range tc.scriptPath {
+ scriptPath[i] = prefix + path
+ }
+ } else {
+ cssPath = tc.cssPath
+ scriptPath = tc.scriptPath
+ }
+
data["siteinfo"] = siteInfo
data["baseURL"] = ""
if parsedUrl, err := url.Parse(siteInfo.General.SiteUrl); err == nil {
data["baseURL"] = parsedUrl.Path
}
- data["scriptPath"] = tc.scriptPath
- data["cssPath"] = tc.cssPath
+ data["scriptPath"] = scriptPath
+ data["cssPath"] = cssPath
data["keywords"] = siteInfo.Keywords
if siteInfo.Description == "" {
siteInfo.Description = siteInfo.General.Description