-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
81 lines (66 loc) · 1.94 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
package main
import (
"fmt"
"os"
"regexp"
"runtime"
"github.com/atmoz/ply/fileutil"
"github.com/docopt/docopt-go"
)
var site Site
func main() {
usage := `ply - recursive markdown to HTML converter
Usage:
ply [options] [<source-path>] [<target-path>]
ply -h|--help
Options:
--include-markdown Include markdown files in target
--include-template Include template files in target
--pretty-urls Use <path>/index.html trick for pretty urls
--keep-links Do NOT replace internal *.md links with *.html
--ignore=<regex> File names to ignore (defaults to "/\.")
--allow-exec Allow templates to execute commands (BE CAREFUL!)
`
args, _ := docopt.ParseDoc(usage)
site.SourcePath, _ = args.String("<source-path>")
site.TargetPath, _ = args.String("<target-path>")
site.includeMarkdown, _ = args.Bool("--include-markdown")
site.includeTemplate, _ = args.Bool("--include-template")
site.prettyUrls, _ = args.Bool("--pretty-urls")
site.keepLinks, _ = args.Bool("--keep-links")
site.allowExec, _ = args.Bool("--allow-exec")
argIgnore, _ := args.String("--ignore")
if argIgnore != "" {
var err error
site.copyOptions = new(fileutil.CopyOptions)
re, err := regexp.Compile(argIgnore)
if err != nil {
fail(err)
}
site.copyOptions.IgnoreRegex = append(site.copyOptions.IgnoreRegex, re)
}
if err := site.Init(); err != nil {
fail(err)
}
if err := site.Build(); err != nil {
fail(err)
}
fmt.Println(len(site.Pages), "pages")
PrintMemUsage()
}
func fail(err error) {
fmt.Println("FATAL:", err)
os.Exit(1)
}
func PrintMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}