-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
59 lines (53 loc) · 1 KB
/
generate.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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
)
var (
wg = &sync.WaitGroup{}
cmd = flag.String("c", "gen", "Command to run [gen/clean]")
)
func main() {
flag.Parse()
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
switch strings.ToLower(*cmd) {
case "gen":
if !info.IsDir() && strings.HasSuffix(path, ".md") {
// TODO: Replace with PEGN-based parser
wg.Add(1)
go func() {
fmt.Printf("Rendering %s ...\n", path)
out := fmt.Sprintf("%s/index.html", filepath.Dir(path))
err = exec.Command("pandoc", path, "-o", out).Run()
if err != nil {
log.Println(err)
}
wg.Done()
}()
}
case "clean":
if !info.IsDir() && strings.HasSuffix(path, ".html") {
wg.Add(1)
go func() {
fmt.Printf("Removing %s ...\n", path)
os.Remove(path)
wg.Done()
}()
}
}
return nil
})
if err != nil {
panic(err)
}
wg.Wait()
}