aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--render.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/render.go b/render.go
index fe6c2f1..83416f5 100644
--- a/render.go
+++ b/render.go
@@ -2,6 +2,7 @@ package main
import (
"net/http"
+ "strings"
"text/template"
)
@@ -11,10 +12,33 @@ func renderTemplate(w http.ResponseWriter, tmplPath string, p *Posts) (err error
return err
}
- err = t.Execute(w, p)
+ data := combineData(tmplPath, p)
+
+ err = t.Execute(w, data)
if err != nil {
return err
}
return nil
}
+
+func combineData(path string, p *Posts) map[string]interface{} {
+ splitPath := strings.Split(path, "/")
+
+ data := make(map[string]interface{})
+
+ if splitPath[0] == "main" {
+ switch splitPath[1] {
+ case "about":
+ data["Page"] = splitPath[1]
+ default:
+ data["Page"] = splitPath[1]
+ data["Posts"] = p
+ }
+ } else {
+ data["Page"] = splitPath[0]
+ data["Post"] = p.Contents[0]
+ }
+
+ return data
+}