From d0ff1b2d04fc0caf57d99f1d34ce13cf4aae6a1a Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 27 Mar 2019 07:18:52 -0700 Subject: reorg: phase 1 --- cmd/site/html.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'cmd/site/html.go') diff --git a/cmd/site/html.go b/cmd/site/html.go index a645551..ba2b4fa 100644 --- a/cmd/site/html.go +++ b/cmd/site/html.go @@ -8,6 +8,8 @@ import ( "path/filepath" "time" + "christine.website/internal" + "christine.website/internal/blog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "within.website/ln" @@ -30,7 +32,7 @@ func logTemplateTime(ctx context.Context, name string, f ln.F, from time.Time) { func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := opname.With(r.Context(), "renderTemplatePage") - fetag := "W/" + Hash(templateFname, etag) + "-1" + fetag := "W/" + internal.Hash(templateFname, etag) + "-1" f := ln.F{"etag": fetag, "if_none_match": r.Header.Get("If-None-Match")} @@ -74,14 +76,16 @@ func (s *Site) showPost(w http.ResponseWriter, r *http.Request) { } cmp := r.URL.Path[1:] - var p *Post + var p blog.Post + var found bool for _, pst := range s.Posts { if pst.Link == cmp { p = pst + found = true } } - if p == nil { + if !found { w.WriteHeader(http.StatusNotFound) s.renderTemplatePage("error.html", "no such post found: "+r.RequestURI).ServeHTTP(w, r) return -- cgit v1.2.3 From 7e6a1cbd5841b094a7e168f8500075443f31e8e0 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 27 Mar 2019 07:31:57 -0700 Subject: make logging cleaner, etag more --- cmd/site/html.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'cmd/site/html.go') diff --git a/cmd/site/html.go b/cmd/site/html.go index ba2b4fa..9f208af 100644 --- a/cmd/site/html.go +++ b/cmd/site/html.go @@ -91,6 +91,17 @@ func (s *Site) showPost(w http.ResponseWriter, r *http.Request) { return } - s.renderTemplatePage("blogpost.html", p).ServeHTTP(w, r) + const dateFormat = `2006-01-02` + s.renderTemplatePage("blogpost.html", struct { + Title string + Link string + BodyHTML template.HTML + Date string + }{ + Title: p.Title, + Link: p.Link, + BodyHTML: p.BodyHTML, + Date: p.Date.Format(dateFormat), + }).ServeHTTP(w, r) postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc() } -- cgit v1.2.3