-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (53 loc) · 1.32 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
package main
import (
"net/http"
"os"
"path"
"github.com/codegangsta/cli"
"github.com/didip/didip.github.io/engine"
"github.com/didip/didip.github.io/engine/dirwatcher"
"github.com/go-fsnotify/fsnotify"
)
func main() {
blog := engine.NewBlog("Systems & Go")
app := cli.NewApp()
app.Name = "didip.github.io"
app.Usage = "builds Didip's blog."
app.Author = "Didip Kerabat"
app.Email = "didipk@gmail.com"
app.Version = "9001.0.0"
app.Commands = []cli.Command{
{
Name: "server",
ShortName: "serv",
Usage: "Run HTTP server",
Action: func(c *cli.Context) {
// Watches markdown/posts/ directory and auto-generate HTML
go dirwatcher.WatchDir(path.Join(blog.CurrentDir, "markdown", "posts"), func(event fsnotify.Event) {
blog.GenerateAllHTML()
})
http.Handle("/", http.FileServer(http.Dir(".")))
http.ListenAndServe(blog.ServerPort(), nil)
},
},
{
Name: "posts",
Usage: "Posts CRUD operations",
Action: func(c *cli.Context) {
crud := c.Args().First()
if crud == "create" || crud == "new" {
title := c.Args().Get(1)
blog.NewBlankPost(title)
} else if crud == "generate" {
path := c.Args().Get(1)
if path == "" {
blog.GenerateAllHTML()
} else {
blog.GeneratePostHTML(path)
}
}
},
},
}
app.Run(os.Args)
}