-
Notifications
You must be signed in to change notification settings - Fork 47
/
main.go
87 lines (70 loc) · 1.65 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"bytes"
"flag"
"io/ioutil"
"log"
"os"
"path"
)
var (
inFile string
outDir string
skipChecks bool
)
func init() {
flag.StringVar(&inFile, "i", "./jailbreaks.yml", "the jailbreaks data file")
flag.StringVar(&outDir, "o", "./static", "the output directory. is created if it doesn't exist")
flag.BoolVar(&skipChecks, "s", false, "skip URL checks")
flag.Parse()
}
func main() {
jbs, err := getJailbreaks(inFile)
if err != nil {
log.Fatalf("Unable to open jailbreaks file at: %s error: %s", inFile, err)
}
if !skipChecks {
err = validate(jbs)
if err != nil {
log.Printf("Jailbreak URL validation failed, err: %s", err)
}
}
err = os.MkdirAll(outDir, 0755)
if err != nil {
log.Fatalln("Unable to create output directory at: " + outDir)
}
pages := [...]page{
{
base: "base",
template: "index",
data: map[string]interface{}{
"MostRecent": jbs.Jailbreaks[0],
"Jailbreaks": jbs.Jailbreaks[1:],
},
},
{
base: "base",
template: "help",
data: nil,
},
}
for _, page := range pages {
buf := new(bytes.Buffer)
err := renderTemplate(
buf,
page.toHTML(page.template),
page.toHTML(page.base),
page.data,
)
if err != nil {
log.Fatalln("Error rendering `" + page.template + "` template: " + err.Error())
}
outFile := path.Join(outDir, page.toHTML(page.template))
err = ioutil.WriteFile(outFile, buf.Bytes(), 0644)
if err != nil {
log.Fatalln("Error outputting file `" + outFile + "`: " + err.Error())
}
}
// marshal the json and output that to the static folder too, for the "api"
marshalToFile(jbs, path.Join(outDir, "jailbreaks.json"))
}