From 9e14932dc61d223c5ff3f5bcef392a3ce49060be Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Sun, 20 Sep 2026 15:58:17 -0400 Subject: [PATCH] Add Google Calendar link to event page Co-Authored-By: Claude Sonnet 4.6 --- handlers.go | 20 ++++++++++++++++++++ templates/event.html | 3 +++ templates/layout.html | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/handlers.go b/handlers.go index 6b71cd1..e2a3111 100644 --- a/handlers.go +++ b/handlers.go @@ -9,6 +9,7 @@ import ( "html/template" "log" "net/http" + "net/url" "strconv" "strings" @@ -175,6 +176,7 @@ type EventPageData struct { IsAdmin bool BaseURL string DescriptionHTML template.HTML + GCalURL string User *db.User AuthEnabled bool CanEditRsvps bool @@ -184,6 +186,23 @@ type EventPageData struct { PlusOneMax int64 } +func buildGCalURL(event db.Event, baseURL string) string { + params := url.Values{} + params.Set("action", "TEMPLATE") + params.Set("text", event.Title) + if event.Location != "" { + params.Set("location", event.Location) + } + var details strings.Builder + if event.Description != "" { + details.WriteString(event.Description) + details.WriteString("\n\n") + } + details.WriteString(baseURL + "/e/" + event.Slug) + params.Set("details", details.String()) + return "https://calendar.google.com/calendar/render?" + params.Encode() +} + func (s *Server) loadEventPage(r *http.Request, slug string, isAdmin bool) (*EventPageData, error) { event, err := s.q.GetEventBySlug(r.Context(), slug) if err != nil { @@ -273,6 +292,7 @@ func (s *Server) loadEventPage(r *http.Request, slug string, isAdmin bool) (*Eve IsAdmin: isAdmin, BaseURL: s.baseURL, DescriptionHTML: descHTML, + GCalURL: buildGCalURL(event, s.baseURL), User: user, AuthEnabled: s.features.Auth, CanEditRsvps: isAdmin || !s.features.Auth || user != nil, diff --git a/templates/event.html b/templates/event.html index 1e2c050..1dc96e5 100644 --- a/templates/event.html +++ b/templates/event.html @@ -29,6 +29,9 @@ {{if .DescriptionHTML}}
{{.DescriptionHTML}}
{{end}} +
+ 📅 Add to Google Calendar ↗ +