templates/calendar.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | package templates import ( "time" g "go.alanpearce.eu/gomponents" c "go.alanpearce.eu/gomponents/components" . "go.alanpearce.eu/gomponents/html" "go.alanpearce.eu/homestead/internal/calendar" ) func CalendarPage( site SiteSettings, page PageSettings, cal calendar.Calendar, ) g.Node { return Layout(site, page, Calendar(site, cal)) } func Calendar(site SiteSettings, cal calendar.Calendar) g.Node { past := true dates, err := cal.Availability(2) if err != nil { panic(err) } return Div(Class("calendar"), H2(g.Text("Calendar")), P(g.Text("Here you can roughly see when I'm busy in the next two weeks")), Section(Class("calendar-grid"), g.Map(dates, func(date *calendar.CalendarDate) g.Node { if past && date.IsToday() { past = false } return Section(c.Classes{ "day": true, "past": past, "today": date.IsToday(), }, H3( Time( DateTime(date.UTC().Format(time.DateOnly)), g.Text(date.Format("Mon _2"))), ), g.Map(date.Events, func(e *calendar.Event) g.Node { return Div( Class("event"), Time( DateTime(e.StartTime.UTC().Format(time.DateOnly)), g.Text(e.StartTime.Format("15:04")), ), g.Text("–"), Time( DateTime(e.EndTime.UTC().Format(time.DateOnly)), g.Text(e.EndTime.Format("15:04")), ), ) }), ) }), ), Footer( P(g.Textf("Timezone is %s", site.Timezone.String())), ), ) } |