Skip to content

Commit

Permalink
Merge pull request #526 from trheyi/main
Browse files Browse the repository at this point in the history
[add] sui page render wrapper option
  • Loading branch information
trheyi authored Dec 13, 2023
2 parents 0318a2e + 5e3fc81 commit e7d6cd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sui/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (page *Page) BuildHTML(option *BuildOption) (string, error) {

html := string(page.Codes.HTML.Code)

if option.WithWrapper {
html = fmt.Sprintf("<body>%s</body>", html)
}

if !option.IgnoreDocument {
html = string(page.Document)
if page.Codes.HTML.Code != "" {
Expand Down
18 changes: 17 additions & 1 deletion sui/core/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) {
SSR: true,
IgnoreAssetRoot: true,
IgnoreDocument: true,
WithWrapper: true,
KeepPageTag: true,
})

Expand All @@ -59,10 +60,25 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) {
res.Warnings = append(res.Warnings, warnings...)
}

res.HTML, err = doc.Html()
// Block save event
// jsCode := `
// console.log("hello ifrme")
// document.addEventListener('keydown', function (event) {
// const isCtrlOrCmdPressed = event.ctrlKey || event.metaKey;
// const isSPressed = event.key === 's';
// if (isCtrlOrCmdPressed && isSPressed) {
// event.preventDefault();
// console.log('Control/Command + S pressed in iframe! Default save behavior prevented.');
// }
// });
// `
// jsCode := ` console.log("hello ifrme")`
// doc.Find("body").AppendHtml(`<script language="javascript">` + jsCode + `</script>`)
res.HTML, err = doc.Find("body").Html()
if err != nil {
return nil, err
}
// fmt.Println(res.HTML)

var data Data = nil
if page.Codes.DATA.Code != "" {
Expand Down
1 change: 1 addition & 0 deletions sui/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type BuildOption struct {
AssetRoot string `json:"asset_root,omitempty"`
IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"`
IgnoreDocument bool `json:"ignore_document,omitempty"`
WithWrapper bool `json:"with_wrapper,omitempty"`
KeepPageTag bool `json:"keep_page_tag,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
Expand Down

0 comments on commit e7d6cd4

Please sign in to comment.