-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (53 loc) · 1.46 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
package main
import (
"context"
"encoding/json"
"log"
"os"
"path"
vconf "go.prajeen.com/vanity/config"
"go.prajeen.com/vanity/template"
)
func main() {
opts := vconf.ParseCLIOpts()
var config vconf.Config
file, err := os.Open(opts.ConfigFile)
if err != nil {
log.Fatalf("Error opening file: %v", err)
}
err = json.NewDecoder(file).Decode(&config)
if err != nil {
log.Fatalf("Error decoding JSON: %v", err)
}
publicDir := path.Join(opts.OutputDir, "public")
err = os.Mkdir(publicDir, os.ModePerm)
if err != nil {
log.Fatalf("Error creating public directory: %v", err)
}
f, err := os.Create(path.Join(publicDir, "index.html"))
if err != nil {
log.Printf("Error creating index.html for home: %v", err)
}
err = template.Home(config).Render(context.Background(), f)
if err != nil {
log.Printf("Error rendering home: %v", err)
}
log.Printf("Created index.html for home page")
info := vconf.ProcessConfig(config)
for _, v := range info {
err := os.Mkdir(path.Join(publicDir, v.Name), os.ModePerm)
if err != nil {
log.Printf("Error creating directory for %s: %v", v.Name, err)
continue
}
f, err = os.Create(path.Join(publicDir, v.Name, "index.html"))
if err != nil {
log.Printf("Error creating index.html for module %s: %v", v.Name, err)
}
err = template.Module(v).Render(context.Background(), f)
if err != nil {
log.Printf("Error rendering module: %v", err)
}
log.Printf("Created index.html for module %s", v.Name)
}
}