diff options
| author | Christine Dodrill <me@christine.website> | 2019-03-27 07:31:57 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-03-27 07:31:57 -0700 |
| commit | 7e6a1cbd5841b094a7e168f8500075443f31e8e0 (patch) | |
| tree | 24d7d72cdb2113909acd912ab1bc06e5c5259e28 /cmd | |
| parent | d0ff1b2d04fc0caf57d99f1d34ce13cf4aae6a1a (diff) | |
| download | xesite-7e6a1cbd5841b094a7e168f8500075443f31e8e0.tar.xz xesite-7e6a1cbd5841b094a7e168f8500075443f31e8e0.zip | |
make logging cleaner, etag more
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/site/html.go | 13 | ||||
| -rw-r--r-- | cmd/site/main.go | 15 | ||||
| -rw-r--r-- | cmd/site/rss.go | 1 |
3 files changed, 19 insertions, 10 deletions
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() } diff --git a/cmd/site/main.go b/cmd/site/main.go index b6a809f..3719095 100644 --- a/cmd/site/main.go +++ b/cmd/site/main.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "net/http" "os" - "sync" "time" "christine.website/internal/blog" @@ -38,8 +37,14 @@ func main() { ln.FatalErr(context.Background(), err, ln.Action("Build")) } + mux := http.NewServeMux() + mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "OK", http.StatusOK) + }) + mux.Handle("/", s) + ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port}) - http.ListenAndServe(":"+port, s) + http.ListenAndServe(":"+port, mux) } // Site is the parent object for https://christine.website's backend. @@ -53,9 +58,6 @@ type Site struct { mux *http.ServeMux sitemap []byte xffmw *xff.XFF - - templates map[string]*template.Template - tlock sync.RWMutex } func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -169,9 +171,6 @@ func Build() (*Site, error) { s.renderTemplatePage("index.html", nil).ServeHTTP(w, r) }) - s.mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) { - http.Error(w, "OK", http.StatusOK) - }) s.mux.Handle("/metrics", promhttp.Handler()) s.mux.Handle("/resume", middleware.Metrics("resume", s.renderTemplatePage("resume.html", s.Resume))) s.mux.Handle("/blog", middleware.Metrics("blog", s.renderTemplatePage("blogindex.html", s.Posts))) diff --git a/cmd/site/rss.go b/cmd/site/rss.go index 5b2c73a..e03e07f 100644 --- a/cmd/site/rss.go +++ b/cmd/site/rss.go @@ -75,7 +75,6 @@ func (s *Site) createJSONFeed(w http.ResponseWriter, r *http.Request) { return } - w.Header().Set("Content-Type", "application/json") e := json.NewEncoder(w) e.SetIndent("", "\t") |
