Refactor SUI core to conditionally append page components in Compile function

This commit is contained in:
Max 2024-07-25 18:05:21 +08:00
parent 276f29d777
commit 0dbdc0b99b

View file

@ -93,8 +93,10 @@ func (page *Page) Compile(ctx *BuildContext, option *BuildOption) (string, []str
}
// Page Components
rawComponents, _ := jsoniter.MarshalToString(ctx.components)
body.AppendHtml("\n\n" + `<script name="imports" type="json">` + "\n" + rawComponents + "\n</script>\n\n")
if ctx != nil && ctx.components != nil && len(ctx.components) > 0 {
rawComponents, _ := jsoniter.MarshalToString(ctx.components)
body.AppendHtml("\n\n" + `<script name="imports" type="json">` + "\n" + rawComponents + "\n</script>\n\n")
}
page.ReplaceDocument(doc)
html, err := doc.Html()