aboutsummaryrefslogtreecommitdiff
path: root/html.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-07-01 13:20:01 -0700
committerChristine Dodrill <me@christine.website>2018-07-01 13:20:01 -0700
commit599712fab9127013e2d89dadabd839c847730637 (patch)
tree2a69843e6a5fbdb69cf4c4600e5a8693a3c4a708 /html.go
parent7d8c210f1499bce3558f107402f2c7ccf8417e7d (diff)
downloadxesite-599712fab9127013e2d89dadabd839c847730637.tar.xz
xesite-599712fab9127013e2d89dadabd839c847730637.zip
rip out mage
Diffstat (limited to 'html.go')
-rw-r--r--html.go73
1 files changed, 0 insertions, 73 deletions
diff --git a/html.go b/html.go
deleted file mode 100644
index ba304c5..0000000
--- a/html.go
+++ /dev/null
@@ -1,73 +0,0 @@
-package main
-
-import (
- "context"
- "fmt"
- "html/template"
- "net/http"
- "time"
-
- "github.com/Xe/ln"
-)
-
-func logTemplateTime(name string, from time.Time) {
- now := time.Now()
- ln.Log(context.Background(), ln.F{"action": "template_rendered", "dur": now.Sub(from).String(), "name": name})
-}
-
-func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- defer logTemplateTime(templateFname, time.Now())
- s.tlock.RLock()
- defer s.tlock.RUnlock()
-
- var t *template.Template
- var err error
-
- if s.templates[templateFname] == nil {
- t, err = template.ParseFiles("templates/base.html", "templates/"+templateFname)
- if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- ln.Error(context.Background(), err, ln.F{"action": "renderTemplatePage", "page": templateFname})
- fmt.Fprintf(w, "error: %v", err)
- }
-
- ln.Log(context.Background(), ln.F{"action": "loaded_new_template", "fname": templateFname})
-
- s.tlock.RUnlock()
- s.tlock.Lock()
- s.templates[templateFname] = t
- s.tlock.Unlock()
- s.tlock.RLock()
- } else {
- t = s.templates[templateFname]
- }
-
- err = t.Execute(w, data)
- if err != nil {
- panic(err)
- }
- })
-}
-
-func (s *Site) showPost(w http.ResponseWriter, r *http.Request) {
- if r.RequestURI == "/blog/" {
- http.Redirect(w, r, "/blog", http.StatusSeeOther)
- return
- }
-
- var p *Post
- for _, pst := range s.Posts {
- if pst.Link == r.RequestURI[1:] {
- p = pst
- }
- }
-
- if p == nil {
- w.WriteHeader(http.StatusNotFound)
- s.renderTemplatePage("error.html", "no such post found: "+r.RequestURI).ServeHTTP(w, r)
- return
- }
-
- s.renderTemplatePage("blogpost.html", p).ServeHTTP(w, r)
-}