diff options
author | Alex <alex@scerba.org> | 2024-03-13 17:09:48 -0400 |
---|---|---|
committer | Alex Scerba <alex@scerba.org> | 2024-10-29 13:20:01 -0400 |
commit | f97d476b495126fd2474b8e3a2968658395d2a0f (patch) | |
tree | 866ce2531ea9ada192e01faeecd42fc02bc5b0c1 /cmd/http/render.go | |
parent | 99d92792daedc0501886edc7c4e4a9f3768f9b8a (diff) |
Complete restructure
Diffstat (limited to 'cmd/http/render.go')
-rw-r--r-- | cmd/http/render.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/cmd/http/render.go b/cmd/http/render.go new file mode 100644 index 0000000..2ce954d --- /dev/null +++ b/cmd/http/render.go @@ -0,0 +1,36 @@ +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 { + data["Page"] = "Project" + data["Post"] = p.Contents[0] + } + + err = t.Execute(w, data) + if err != nil { + return err + } + + return nil +} |