-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
93 lines (78 loc) · 2.02 KB
/
build.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
88
89
90
91
92
93
package main
import (
"html/template"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"time"
"github.com/russross/blackfriday"
)
var funcs = template.FuncMap{
"readdir": ioutil.ReadDir,
"readfile": ioutil.ReadFile,
"markdown": markdown,
"slug": slug,
"noescape": func(s string) template.HTML { return template.HTML(s) },
}
const (
flags = blackfriday.HTML_USE_XHTML |
blackfriday.HTML_USE_SMARTYPANTS |
blackfriday.HTML_SMARTYPANTS_FRACTIONS |
blackfriday.HTML_SMARTYPANTS_DASHES |
blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
extensions = blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
blackfriday.EXTENSION_TABLES |
blackfriday.EXTENSION_FENCED_CODE |
blackfriday.EXTENSION_AUTOLINK |
blackfriday.EXTENSION_STRIKETHROUGH |
blackfriday.EXTENSION_SPACE_HEADERS |
blackfriday.EXTENSION_HEADER_IDS |
blackfriday.EXTENSION_AUTO_HEADER_IDS |
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK |
blackfriday.EXTENSION_DEFINITION_LISTS
)
func slug(s string) string {
return strings.ToLower(strings.Replace(s, " ", "-", -1))
}
func markdown(b []byte) string {
r := blackfriday.HtmlRenderer(flags, "", "")
return string(blackfriday.MarkdownOptions(b, r, blackfriday.Options{
Extensions: extensions,
}))
}
var tmpl = template.Must(template.New("index").Funcs(funcs).ParseGlob("views/*.html"))
type page struct {
Name string
File string
}
var pages = []page{
{"Features", "Features.md"},
{"Installation", "Installation.md"},
{"Components", "Components.md"},
{"Examples", "Examples.md"},
{"CLI", "CLI.md"},
{"API", "API.md"},
{"Manager", "Manager.md"},
{"Admin API", "Admin_API.md"},
{"Admin HTTP API", "Admin_HTTP_API.md"},
{"Authors", "Authors.md"},
{"License", "License.md"},
}
func main() {
start := time.Now()
data := struct {
Docs string
Pages []page
}{
Docs: filepath.Join("../vinxi/docs"),
Pages: pages,
}
log.Printf("building %s", data.Docs)
err := tmpl.Execute(os.Stdout, data)
if err != nil {
log.Fatalf("error: %s", err)
}
log.Printf("build completed in %s", time.Since(start))
}