@@ -21,20 +21,24 @@ type content struct {
21
21
Body string
22
22
}
23
23
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
+
24
39
func main () {
25
40
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 )
38
42
fs := http .FileServer (http .Dir ("public" ))
39
43
r .Handle ("/" , fs )
40
44
0 commit comments