aboutsummaryrefslogtreecommitdiff
path: root/cmd/site/html.go
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-09-12 18:49:03 -0400
committerGitHub <noreply@github.com>2019-09-12 18:49:03 -0400
commit7a302eb69bfef1ecd0a17e16085bd4359a0ae717 (patch)
treefc6d777b3c4f2af57951f0921de8a334ad4cfee8 /cmd/site/html.go
parent2007492c492be3c32b19fbfcc6b6c1a5cc5ef0e0 (diff)
downloadxesite-7a302eb69bfef1ecd0a17e16085bd4359a0ae717.tar.xz
xesite-7a302eb69bfef1ecd0a17e16085bd4359a0ae717.zip
Series and tags (#74)
* initial support for tags and series * tagging support * oops * Update main.go
Diffstat (limited to 'cmd/site/html.go')
-rw-r--r--cmd/site/html.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/site/html.go b/cmd/site/html.go
index 33bdd0f..a1d5040 100644
--- a/cmd/site/html.go
+++ b/cmd/site/html.go
@@ -6,6 +6,7 @@ import (
"html/template"
"net/http"
"path/filepath"
+ "strings"
"time"
"christine.website/internal"
@@ -69,6 +70,34 @@ var postView = promauto.NewCounterVec(prometheus.CounterOpts{
Help: "The number of views per post or talk",
}, []string{"base"})
+func (s *Site) listSeries(w http.ResponseWriter, r *http.Request) {
+ s.renderTemplatePage("series.html", s.Series).ServeHTTP(w, r)
+}
+
+func (s *Site) showSeries(w http.ResponseWriter, r *http.Request) {
+ if r.RequestURI == "/blog/series/" {
+ http.Redirect(w, r, "/blog/series", http.StatusSeeOther)
+ return
+ }
+
+ series := filepath.Base(r.URL.Path)
+ var posts []blog.Post
+
+ for _, p := range s.Posts {
+ if p.Series == series {
+ posts = append(posts, p)
+ }
+ }
+
+ s.renderTemplatePage("serieslist.html", struct {
+ Name string
+ Posts []blog.Post
+ }{
+ Name: series,
+ Posts: posts,
+ }).ServeHTTP(w, r)
+}
+
func (s *Site) showTalk(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/talks/" {
http.Redirect(w, r, "/talks", http.StatusSeeOther)
@@ -136,17 +165,29 @@ func (s *Site) showPost(w http.ResponseWriter, r *http.Request) {
return
}
+ var tags string
+
+ if len(p.Tags) != 0 {
+ for _, t := range p.Tags {
+ tags = tags + " #" + strings.ReplaceAll(t, "-", "")
+ }
+ }
+
const dateFormat = `2006-01-02`
s.renderTemplatePage("blogpost.html", struct {
Title string
Link string
BodyHTML template.HTML
Date string
+ Series string
+ Tags string
}{
Title: p.Title,
Link: p.Link,
BodyHTML: p.BodyHTML,
Date: p.Date.Format(dateFormat),
+ Series: strings.ReplaceAll(p.Series, "-", ""),
+ Tags: tags,
}).ServeHTTP(w, r)
postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc()
}