-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (73 loc) · 1.55 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
package main
import (
//"strconv"
"github.com/fripSide/HexGo-CI/hexgo"
//"HexGo-CI/hexgo"
"os"
"fmt"
"io/ioutil"
"path"
"flag"
)
/*
TODO:
1. 完善CSS。
2. 支持Domain,目录,或者大纲(markdown ToC功能)。
3. 支持Github Pages,重构代码。
4. 集成CI并部署。
速度上线,用约定俗成来代替配置。
*/
const (
workDir = "/Users/fripside/Go/src/HexGo/"
DEBUG = true
ARG_GEN = "gen"
ARG_DEV = "dev"
)
// 从github pull新内容
func Update() {
}
func GenBookCache() *hexgo.BlogTheme {
d, err := os.Getwd()
dir := workDir
if err == nil {
dir = d + "/"
}
fmt.Println("Run Build In: ", dir)
//fmt.Println("Book Content: ", bookList.Books["go/"].Content)
//confDir := path.Join(dir, "conf")
confDir := dir
cacheDir := path.Join(dir, "cache")
theme := hexgo.NewBlogTheme(confDir, cacheDir)
return theme
}
func Dev() {
h := hexgo.CreateApp(":8080")
theme := GenBookCache()
h.SetupFunc = func() {
fmt.Println("Restart Func")
theme := GenBookCache()
h.SetRegisterMap(theme.RequestMap)
}
fmt.Println("exec restart func")
h.RegisterPages(theme)
h.RegisterStaticDir("/static/", "cache/static")
h.RegisterStaticDir("/image/","cache/image")
h.Get("/css", func(context *hexgo.Context) {
fp, _ := ioutil.ReadFile(workDir + "conf/index.html")
context.Writer.Write(fp)
})
if DEBUG {
hexgo.LiveReload(h)
} else {
h.Run()
}
}
func main() {
action := flag.String("action", "dev", "-action [dev] or [gen]")
flag.Parse()
if *action == "gen" {
GenBookCache()
} else if *action == "dev" {
Dev()
}
}