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: render every entry stylesheet, not only the first
Xan Torres88c5ef666df0
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex 8290d8b6..3c102166 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -57,8 +57,11 @@ import (var SiteUrl = ""type TemplateController struct {- scriptPath []string- cssPath string+ scriptPath []string+ // cssPath lists every stylesheet the frontend build emits, in document+ // order; a build that emits more than one entry stylesheet needs all of+ // them, not just the first, or server-rendered pages come back unstyled.+ cssPath []stringtemplateRenderController *templaterender.TemplateRenderControllersiteInfoService siteinfo_common.SiteInfoCommonServiceeventQueueService eventqueue.Service@@ -85,7 +88,7 @@ func NewTemplateController(questionService: questionService,}}-func GetStyle() (script []string, css string) {+func GetStyle() (script []string, css []string) {file, err := ui.Build.ReadFile("build/index.html")if err != nil {return@@ -131,9 +134,9 @@ func GetStyle() (script []string, css string) {script = append(script, src)}case "link":- if css == "" && isStylesheet(n) {+ if isStylesheet(n) {if href, ok := attr(n, "href"); ok && href != "" {- css = href+ css = append(css, href)}}}@@ -602,7 +605,7 @@ func (tc *TemplateController) Page404(ctx *gin.Context) {func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteInfo *schema.TemplateSiteInfoResp, data gin.H) {prefix := ""- cssPath := ""+ cssPath := make([]string, len(tc.cssPath))scriptPath := make([]string, len(tc.scriptPath))_ = plugin.CallCDN(func(fn plugin.CDN) error {@@ -614,7 +617,9 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteIif prefix[len(prefix)-1:] == "/" {prefix = strings.TrimSuffix(prefix, "/")}- cssPath = prefix + tc.cssPath+ for i, path := range tc.cssPath {+ cssPath[i] = prefix + path+ }for i, path := range tc.scriptPath {scriptPath[i] = prefix + path}diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.goindex 273b7df8..6b4b4b79 100644--- a/internal/controller/template_controller_test.go+++ b/internal/controller/template_controller_test.go@@ -53,4 +53,8 @@ func TestGetStyleResolvesBuiltAssets(t *testing.T) {require.NotEmpty(t, css,"no stylesheet href parsed out of %s; server-rendered pages would load unstyled", builtIndexPath)+ for i, href := range css {+ require.NotEmpty(t, href,+ "stylesheet href %d parsed out of %s is empty; server-rendered pages would load unstyled", i, builtIndexPath)+ }}diff --git a/ui/template/header.html b/ui/template/header.htmlindex d5d9a18a..f9f0468b 100644--- a/ui/template/header.html+++ b/ui/template/header.html@@ -34,7 +34,9 @@<link rel="canonical" href="{{.siteinfo.Canonical}}" /><link rel="manifest" href="{{$.baseURL}}/manifest.json" /><link rel="search" type="application/opensearchdescription+xml" href="{{$.baseURL}}/opensearch.xml" title="{{.siteinfo.General.Name}}" />- <link href="{{.cssPath}}" rel="stylesheet" />+ {{range $path := .cssPath}}+ <link href="{{$path}}" rel="stylesheet" />+ {{end}}<link href="{{$.baseURL}}/custom.css" rel="stylesheet" /><linkrel="icon"