-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml_template.go
58 lines (46 loc) · 1.21 KB
/
html_template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
_ "embed"
"fmt"
"os"
)
const htmlHeader = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>%s</title>
%s
<script>%s</script>
</head>
<body>
<div id="widget" style="display:none;"></div>
<div id="widget-starter" style="float:right;"><a id="widget-starter-button" href="javascript:void(0);">*</a></div>
`
//go:embed customize.css
var customCss string
//go:embed myapp.js
var javaScriptExample string
func GetInternalCssBlock(defaultCssPath string) string {
defaultCss, err := os.ReadFile(defaultCssPath)
if err != nil {
panic(err)
}
return "<style>" + string(defaultCss) + "\n" + customCss + "</style>"
}
func GetExternalCssBlock() string {
return `<link rel="stylesheet" href="DefaultStyle.css">
<link rel="stylesheet" href="customize.css">`
}
func GenHtmlHeader(title string, inlineCss bool, defaultCssPath string, javaScript string) string {
var cssBlock string
if inlineCss {
cssBlock = GetInternalCssBlock(defaultCssPath)
} else {
cssBlock = GetExternalCssBlock()
}
return fmt.Sprintf(htmlHeader, title, cssBlock, javaScript)
}
const htmlFooter = `</body>
</html>
`