{{/* The public agenda: one grid per month, all of them built here. Every month in the span is rendered and assets/js/agenda.js shows one at a time. Two things fall out of building them all rather than fetching a month at a time: * **With JavaScript off, every month is on the page**, stacked, each under its own heading. Nothing is hidden from a reader who has no script, and nothing is hidden from a crawler either. * Moving between months is instant and makes no request. The weekday arithmetic is the awkward part: the length of a month comes from a table plus a leap-year check, because there is nothing to call for it. It looks like something simpler was missed, and it is not. */}} {{ define "main" }} {{ $lang := .Site.Language.Lang }} {{ $events := where (where .Site.RegularPages "Section" "post") "Params.event_date" "!=" nil }} {{/* The span to render. Every month that has an event, and — whatever the events say — this month and the eleven after it, so there is always a year ahead to look at. Without that last part the agenda stopped dead at the last month anybody had announced something in: the → went grey in December and January could not be reached, which reads as broken rather than as empty. A month with nothing in it says so. */}} {{ $months := slice }} {{ range $events }}{{ $months = $months | append (substr .Params.event_date 0 7) }}{{ end }} {{ $months = $months | append (now.Format "2006-01") ((now.AddDate 0 11 0).Format "2006-01") }} {{ $months = sort (uniq $months) }} {{ $from := index $months 0 }} {{ $to := index $months (sub (len $months) 1) }} {{/* Filled in, so a month between two events can still be visited. */}} {{ $span := slice }} {{ range $y := seq (int (substr $from 0 4)) (int (substr $to 0 4)) }} {{ range $m := seq 1 12 }} {{ $key := printf "%04d-%02d" $y $m }} {{ if and (ge $key $from) (le $key $to) }}{{ $span = $span | append $key }}{{ end }} {{ end }} {{ end }} {{ $script := resources.Get "js/agenda.js" | minify | fingerprint }}

{{ .Title }}

{{ with .Content }}
{{ . }}
{{ end }} {{ range $key := $span }} {{ $firstDay := printf "%s-01" $key }} {{/* Through the date rather than off the string: `int "08"` is an error, because Go reads a leading zero as octal and 8 is not an octal digit. That sat here unnoticed for as long as the span only ever ran from the first event to the last — August and September were never in it. The moment the agenda gained a year of empty months ahead, the build stopped. `Format "1"` is the month with no padding. */}} {{ $asTime := $firstDay | time.AsTime }} {{ $year := $asTime.Year }} {{ $month := int ($asTime.Format "1") }} {{/* Days in the month: a table, with February decided by the leap rule — every four years, not every hundred, except every four hundred. */}} {{ $lengths := slice 31 28 31 30 31 30 31 31 30 31 30 31 }} {{ $days := index $lengths (sub $month 1) }} {{ if eq $month 2 }} {{ if or (and (eq (mod $year 4) 0) (ne (mod $year 100) 0)) (eq (mod $year 400) 0) }} {{ $days = 29 }} {{ end }} {{ end }} {{/* Monday first, as in Austria and most of Latin America. Go names the weekday; this turns the name into a column offset. */}} {{ $offsets := dict "Mon" 0 "Tue" 1 "Wed" 2 "Thu" 3 "Fri" 4 "Sat" 5 "Sun" 6 }} {{ $lead := index $offsets ($asTime.Format "Mon") }}

{{ partial "month-name.html" (dict "month" $month "lang" $lang) }} {{ $year }}

{{/* The column header, at every width. It is what lets the weekday inside each cell be a label for a screen reader rather than ink in a fifty-pixel box. */}}
    {{ if gt $lead 0 }}{{ range seq $lead }}{{ end }}{{ end }} {{ range $day := seq 1 $days }} {{ $date := printf "%s-%02d" $key $day }} {{/* By the hour, so two things on one day read in the order they happen rather than in the order they were announced. The private calendar has sorted this way since it was written (apps/board/events.py: `ORDER BY starts_on, COALESCE(starts_at, '99:99')`), and the two show the same events to the same people. An event with no time sorts first here, which is right: all day begins before the evening does. */}} {{ $onThisDay := sort (where $events "Params.event_date" $date) "Params.event_time" }} {{ $weekday := mod (add (sub $day 1) $lead) 7 }}
  1. {{ partial "weekday-name.html" (dict "weekday" $weekday "lang" $lang) }} {{ $day }} {{ with $onThisDay }} {{/* A phone cell is about fifty pixels wide, which holds a number and some dots and nothing else. The dots link to this day's block in the list below, so the month stays a month and the titles stay readable. */}} {{ range first 4 . }}{{ end }} {{ end }} {{ range $onThisDay }}{{ partial "agenda-event.html" . }}{{ end }}
  2. {{ end }}
{{ $inMonth := where (where $events "Params.event_date" "ge" (printf "%s-01" $key)) "Params.event_date" "le" (printf "%s-31" $key) }} {{/* Only the days that have something in them, and only on a phone — above 640px every title is already in its cell. */}} {{ with $inMonth }}
{{ range $day := seq 1 $days }} {{ $date := printf "%s-%02d" $key $day }} {{ with sort (where $events "Params.event_date" $date) "Params.event_time" }}

{{ $day }} {{ partial "month-name.html" (dict "month" $month "lang" $lang) }} {{ $year }}

{{ range . }}{{ partial "agenda-event.html" . }}{{ end }}
{{ end }} {{ end }}
{{ end }} {{ if not $inMonth }}

{{ partial "t.html" (dict "key" "noevents" "lang" $lang) }}

{{ end }}
{{ end }}
{{ end }}