aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-11-01 17:48:19 -0400
committerGitHub <noreply@github.com>2019-11-01 17:48:19 -0400
commit5f4ee89e57060dc9c119d84ac5700784c343b8d9 (patch)
tree2a18debdceae9d538d0e9a9c451c10022de472ee /cmd
parent42371916d83af7fc2e4ca053d963e6cfab15a8f1 (diff)
downloadxesite-5f4ee89e57060dc9c119d84ac5700784c343b8d9.tar.xz
xesite-5f4ee89e57060dc9c119d84ac5700784c343b8d9.zip
Art gallery (#91)
* implement art gallery * update dates * gallery: update tags * gofmt * templates/gallerypost: add hashtags
Diffstat (limited to 'cmd')
-rw-r--r--cmd/site/html.go53
-rw-r--r--cmd/site/main.go20
2 files changed, 68 insertions, 5 deletions
diff --git a/cmd/site/html.go b/cmd/site/html.go
index 558dc71..912ad77 100644
--- a/cmd/site/html.go
+++ b/cmd/site/html.go
@@ -98,6 +98,59 @@ func (s *Site) showSeries(w http.ResponseWriter, r *http.Request) {
}).ServeHTTP(w, r)
}
+func (s *Site) showGallery(w http.ResponseWriter, r *http.Request) {
+ if r.RequestURI == "/gallery/" {
+ http.Redirect(w, r, "/gallery", http.StatusSeeOther)
+ return
+ }
+
+ cmp := r.URL.Path[1:]
+ var p blog.Post
+ var found bool
+ for _, pst := range s.Gallery {
+ 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
+ }
+
+ var tags string
+ if len(p.Tags) != 0 {
+ for _, t := range p.Tags {
+ tags = tags + " #" + strings.ReplaceAll(t, "-", "")
+ }
+ }
+
+ h := s.renderTemplatePage("gallerypost.html", struct {
+ Title string
+ Link string
+ BodyHTML template.HTML
+ Date string
+ Tags string
+ Image string
+ }{
+ Title: p.Title,
+ Link: p.Link,
+ BodyHTML: p.BodyHTML,
+ Date: internal.IOS13Detri(p.Date),
+ Tags: tags,
+ Image: p.ImageURL,
+ })
+
+ if h == nil {
+ panic("how did we get here?")
+ }
+
+ h.ServeHTTP(w, r)
+ postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc()
+}
+
func (s *Site) showTalk(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/talks/" {
http.Redirect(w, r, "/talks", http.StatusSeeOther)
diff --git a/cmd/site/main.go b/cmd/site/main.go
index 391b56b..eaefb5d 100644
--- a/cmd/site/main.go
+++ b/cmd/site/main.go
@@ -55,10 +55,11 @@ func main() {
// Site is the parent object for https://christine.website's backend.
type Site struct {
- Posts blog.Posts
- Talks blog.Posts
- Resume template.HTML
- Series []string
+ Posts blog.Posts
+ Talks blog.Posts
+ Gallery blog.Posts
+ Resume template.HTML
+ Series []string
rssFeed *feeds.Feed
jsonFeed *jsonfeed.Feed
@@ -82,7 +83,7 @@ func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
middleware.RequestID(s.xffmw.Handler(ex.HTTPLog(s.mux))).ServeHTTP(w, r)
}
-var arbDate = time.Date(2019, time.September, 12, 0, 0, 0, 0, time.UTC)
+var arbDate = time.Date(2019, time.November, 2, 0, 0, 0, 0, time.UTC)
// Build creates a new Site instance or fails.
func Build() (*Site, error) {
@@ -157,9 +158,16 @@ func Build() (*Site, error) {
}
s.Talks = talks
+ gallery, err := blog.LoadPosts("./gallery", "gallery")
+ if err != nil {
+ return nil, err
+ }
+ s.Gallery = gallery
+
var everything blog.Posts
everything = append(everything, posts...)
everything = append(everything, talks...)
+ everything = append(everything, gallery...)
sort.Sort(sort.Reverse(everything))
@@ -208,6 +216,7 @@ func Build() (*Site, error) {
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)))
s.mux.Handle("/talks", middleware.Metrics("talks", s.renderTemplatePage("talkindex.html", s.Talks)))
+ s.mux.Handle("/gallery", middleware.Metrics("gallery", s.renderTemplatePage("galleryindex.html", s.Gallery)))
s.mux.Handle("/contact", middleware.Metrics("contact", s.renderTemplatePage("contact.html", nil)))
s.mux.Handle("/blog.rss", middleware.Metrics("blog.rss", http.HandlerFunc(s.createFeed)))
s.mux.Handle("/blog.atom", middleware.Metrics("blog.atom", http.HandlerFunc(s.createAtom)))
@@ -216,6 +225,7 @@ func Build() (*Site, error) {
s.mux.Handle("/blog/series", http.HandlerFunc(s.listSeries))
s.mux.Handle("/blog/series/", http.HandlerFunc(s.showSeries))
s.mux.Handle("/talks/", middleware.Metrics("talks", http.HandlerFunc(s.showTalk)))
+ s.mux.Handle("/gallery/", middleware.Metrics("gallery", http.HandlerFunc(s.showGallery)))
s.mux.Handle("/css/", http.FileServer(http.Dir(".")))
s.mux.Handle("/static/", http.FileServer(http.Dir(".")))
s.mux.HandleFunc("/sw.js", func(w http.ResponseWriter, r *http.Request) {