Skip to content

Commit 89fcd94

Browse files
committed
Update main.go
1 parent 434a776 commit 89fcd94

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

main.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@ type content struct {
2121
Body string
2222
}
2323

24+
func generateHandler(w http.ResponseWriter, r *http.Request) {
25+
// Pull the latest Git version
26+
exec.Command("git checkout -f").Output()
27+
exec.Command("git pull").Output()
28+
29+
// Generate index.html file
30+
input, _ := ioutil.ReadFile(readmePath)
31+
body := string(gfm.Markdown(input))
32+
c := &content{Body: body}
33+
t := template.Must(template.ParseFiles(tmplPath))
34+
f, _ := os.Create(indexPath)
35+
t.Execute(f, c)
36+
w.Write([]byte("Page generated"))
37+
}
38+
2439
func main() {
2540
r := mux.NewRouter()
26-
r.HandleFunc("/generate", func(w http.ResponseWriter, r *http.Request) {
27-
exec.Command("git checkout -f").Output()
28-
exec.Command("git pull").Output()
29-
30-
input, _ := ioutil.ReadFile(readmePath)
31-
body := string(gfm.Markdown(input))
32-
c := &content{Body: body}
33-
t := template.Must(template.ParseFiles(tmplPath))
34-
f, _ := os.Create(indexPath)
35-
t.Execute(f, c)
36-
w.Write([]byte("Page generated"))
37-
})
41+
r.HandleFunc("/generate", generateHandler)
3842
fs := http.FileServer(http.Dir("public"))
3943
r.Handle("/", fs)
4044

0 commit comments

Comments
 (0)