aboutsummaryrefslogtreecommitdiff
path: root/cmd/site/html.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-05-21 21:47:09 -0400
committerGitHub <noreply@github.com>2019-05-21 21:47:09 -0400
commitd64c666255665c5e03812c47e70d6edb46432510 (patch)
tree1dd44e77f7d57a5a52ccfa0fe96fc073cb3da2fe /cmd/site/html.go
parenta275fc754b4c82a81ba06f0f3cbddb39946db1ac (diff)
downloadxesite-d64c666255665c5e03812c47e70d6edb46432510.tar.xz
xesite-d64c666255665c5e03812c47e70d6edb46432510.zip
add talks support (#40)
* add talks support * gosimplify
Diffstat (limited to 'cmd/site/html.go')
-rw-r--r--cmd/site/html.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/cmd/site/html.go b/cmd/site/html.go
index 9f208af..b3fa484 100644
--- a/cmd/site/html.go
+++ b/cmd/site/html.go
@@ -66,9 +66,53 @@ func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.H
var postView = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "posts_viewed",
- Help: "The number of views per post",
+ Help: "The number of views per post or talk",
}, []string{"base"})
+func (s *Site) showTalk(w http.ResponseWriter, r *http.Request) {
+ if r.RequestURI == "/talks/" {
+ http.Redirect(w, r, "/talks", http.StatusSeeOther)
+ return
+ }
+
+ cmp := r.URL.Path[1:]
+ var p blog.Post
+ var found bool
+ for _, pst := range s.Talks {
+ if pst.Link == cmp {
+ p = pst
+ found = true
+ }
+ }
+
+ if !found {
+ w.WriteHeader(http.StatusNotFound)
+ s.renderTemplatePage("error.html", "no such post found: "+r.RequestURI).ServeHTTP(w, r)
+ return
+ }
+
+ const dateFormat = `2006-01-02`
+ h := s.renderTemplatePage("talkpost.html", struct {
+ Title string
+ Link string
+ BodyHTML template.HTML
+ Date string
+ SlidesLink string
+ }{
+ Title: p.Title,
+ Link: p.Link,
+ BodyHTML: p.BodyHTML,
+ Date: p.Date.Format(dateFormat),
+ SlidesLink: p.SlidesLink,
+ })
+
+ if h == nil {
+ panic("how did we get here?")
+ }
+
+ h.ServeHTTP(w, r)
+}
+
func (s *Site) showPost(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/blog/" {
http.Redirect(w, r, "/blog", http.StatusSeeOther)