aboutsummaryrefslogtreecommitdiff
path: root/cmd/http/render.go
diff options
context:
space:
mode:
authorAlex Scerba <alex@scerba.org>2024-09-27 18:56:29 -0400
committerAlex Scerba <alex@scerba.org>2024-09-27 18:56:29 -0400
commit2782bafcfdb69ef7b69a51a717a6bd35095e9369 (patch)
tree32d69f68fe2dbc6b9cc5a5ac8ff970d79f348156 /cmd/http/render.go
parent1208c2e7e7e79cfe122f8d5f38160a0611cc9dfe (diff)
Add base files
Diffstat (limited to 'cmd/http/render.go')
-rw-r--r--cmd/http/render.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/http/render.go b/cmd/http/render.go
new file mode 100644
index 0000000..9c01e57
--- /dev/null
+++ b/cmd/http/render.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "net/http"
+ "strings"
+ "text/template"
+)
+
+func renderTemplate(w http.ResponseWriter, tmplPath string, p *Posts) (err error) {
+ t, err := template.ParseFiles("html/master.tmpl.html", "html/"+tmplPath+".tmpl.html")
+ if err != nil {
+ return err
+ }
+
+ splitPath := strings.Split(tmplPath, "/")
+
+ data := make(map[string]interface{})
+
+ // If were loading the index, set page to 'Index' and pass through all posts.
+ // Otherwise, set page to 'Projects' and pass through the first post (should only be one
+ // coming in)
+ if splitPath[0] == "index" {
+ data["Page"] = "Index"
+ data["Posts"] = p
+ } else if splitPath[0] == "about" {
+ data["Page"] = "About"
+ data["Posts"] = nil
+ } else {
+ data["Page"] = "Project"
+ data["Post"] = p.Contents[0]
+ }
+
+ err = t.Execute(w, data)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}