Skip to content

Commit

Permalink
Fix template scrollbars
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Dec 15, 2020
1 parent 69dd56e commit 42ca466
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/generate-templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
out.Write([]byte("package templates\n\nvar Get = map[string]string{\n"))
for _, fileInfo := range files {
if strings.HasSuffix(fileInfo.Name(), ".html") {
out.Write([]byte(strings.TrimSuffix(fileInfo.Name(), ".html") + ": `"))
out.Write([]byte("\"" + strings.TrimSuffix(fileInfo.Name(), ".html") + "\"" + ": `"))
file, _ := os.Open(path.Join(templatesDir, fileInfo.Name()))
io.Copy(out, file)
out.Write([]byte("`,\n"))
Expand Down
19 changes: 16 additions & 3 deletions server/web-preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,27 @@ func (serv *UploadServer) handleWebPreview(c *gin.Context) {
item.wg.Wait()

// Prepare html and send it to the client
style := "display: flex; justify-content: center;"
style := `
body {
display: flex; justify-content: center;
}`
if !center {
style = ""
style = `
body {
overflow: hidden;
}
#kiwi-embed-container {
position: absolute;
top: 0;
left: 0;
bottom: 0;
overflow: auto;
}`
}
templateLock.RLock()
htmlData := strings.Replace(template, "{{body.html}}", item.html, -1)
templateLock.RUnlock()
htmlData = strings.Replace(htmlData, "/* style.body */", style, -1)
htmlData = strings.Replace(htmlData, "/* style.extras */", style, -1)
c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(htmlData))
}

Expand Down
4 changes: 1 addition & 3 deletions templates/embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
margin: 0;
padding: 0;
}
body {
/* style.body */
}
.kiwi-embed-image {
display: block;
}
/* style.extras */
</style>
<script>
let last_width = 0;
Expand Down
6 changes: 2 additions & 4 deletions templates/templates.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package templates

var Get = map[string]string{
"Embed": `<!DOCTYPE html>
"Embed": `<!DOCTYPE html>
<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
}
body {
/* style.body */
}
.kiwi-embed-image {
display: block;
}
/* style.extras */
</style>
<script>
let last_width = 0;
Expand Down

0 comments on commit 42ca466

Please sign in to comment.