-
Notifications
You must be signed in to change notification settings - Fork 14
/
preview.go
58 lines (52 loc) · 1.16 KB
/
preview.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 (
"bytes"
"log"
"os"
"path/filepath"
"text/template"
)
func createPreview(appPath string) {
const tpl = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>demo</title>
</head>
<body>
</body>
<script>
function add(varclass) {
const newDiv = document.createElement("pre")
newDiv.style.fontFamily = varclass[1]
newDiv.appendChild(document.createTextNode(varclass[0] + " => " + varclass[1] + ":\n1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
document.body.appendChild(newDiv)
}
[{{ range $_, $value := .Fonts }}
["{{ $value.ValveFont }}", "{{ $value.ReplaceFont }}"],{{ end }}
].forEach(ele => {
add(ele)
})
</script>
</html>`
t := template.Must(template.New("preview").Parse(tpl))
if !config.Customize {
config.Default()
}
data := struct {
Fonts []FontStruct
}{
Fonts: config.Fonts,
}
var buf bytes.Buffer
if err := t.Execute(&buf, data); err != nil {
if err != nil {
log.Fatal(err)
}
}
if err := os.WriteFile(filepath.Join(appPath, "demo.htm"), buf.Bytes(), 0644); err != nil {
log.Fatal(err)
}
}