Make sure missing data is handled gracefully
All checks were successful
/ build (pull_request) Successful in 23s
/ cleanup-staging (pull_request) Successful in 3s

This commit is contained in:
Stefan Bethke 2026-10-16 18:58:29 +02:00
commit 79eac5c7c5
2 changed files with 23 additions and 10 deletions

View file

@ -6,10 +6,20 @@ Usage: {{< schedule >}} on a section page (the event is the section name),
or {{< schedule 39c3 >}}.
*/ -}}
{{- $event := .Get 0 | default .Page.Section -}}
{{- $schedule := index hugo.Data.schedule $event -}}
{{- if not $schedule -}}
{{- errorf "schedule: no data file data/schedule/%s.yaml: %s" $event .Position -}}
{{- /* A missing or empty data file, or one without tours, renders nothing but a warning. */ -}}
{{- $file := false -}}
{{- $days := slice -}}
{{- with hugo.Data.schedule -}}
{{- if isset . $event }}{{ $file = true }}{{ end -}}
{{- with index . $event }}{{ with .days }}{{ $days = . }}{{ end }}{{ end -}}
{{- end -}}
{{- $tourCount := 0 -}}
{{- range $days }}{{ with .tours }}{{ $tourCount = add $tourCount (len .) }}{{ end }}{{ end -}}
{{- if not $file -}}
{{- warnidf "warning-schedule-empty" "schedule: no data file data/schedule/%s.yaml: %s" $event .Position -}}
{{- else if not $tourCount -}}
{{- warnidf "warning-schedule-empty" "schedule: no tours in data/schedule/%s.yaml: %s" $event .Position -}}
{{- else -}}
{{- $id := printf "schedule-%s" $event | anchorize -}}
{{- /* Tour page titles start with the event name ("39C3 Rote Flora"); the cards don't need it. */ -}}
{{- $prefix := printf `(?i)^%s\s+` $event -}}
@ -20,7 +30,7 @@ Every hour from the first to the last tour starts a new row ($hours) with a line
so an hour without tours still gets a row.
*/ -}}
{{- $slotCount := dict -}}
{{- range $schedule.days -}}
{{- range $days -}}
{{- $count := dict -}}
{{- range .tours -}}
{{- $count = merge $count (dict .time (add (index $count .time | default 0) 1)) -}}
@ -51,17 +61,17 @@ so an hour without tours still gets a row.
{{- end -}}
<div class="schedule" id="{{ $id }}" data-schedule>
<div class="schedule__picker" role="group" aria-label="{{ i18n "schedule_pick_day" }}" hidden>
{{- range $schedule.days }}
{{- range $days }}
<button type="button" class="schedule__pick" aria-controls="{{ $id }}-day-{{ .day }}" aria-pressed="false" data-date="{{ .date }}">{{ i18n "schedule_day" (dict "Day" .day) }} <span class="schedule__pick-date">{{ time.AsTime .date | time.Format "2.1." }}</span></button>
{{- end }}
</div>
<div class="schedule__days" style="--schedule-days: {{ len $schedule.days }}; --schedule-rows: {{ $rows }}">
{{- range $column, $day := $schedule.days }}
<div class="schedule__days" style="--schedule-days: {{ len $days }}; --schedule-rows: {{ $rows }}">
{{- range $column, $day := $days }}
<section class="schedule__day" id="{{ $id }}-day-{{ .day }}" aria-labelledby="{{ $id }}-day-{{ .day }}-title" style="--schedule-column: {{ add $column 1 }}">
<h2 class="schedule__day-title" id="{{ $id }}-day-{{ .day }}-title">{{ i18n "schedule_day" (dict "Day" .day) }} <span class="schedule__date">{{ time.AsTime .date | time.Format "Mon 2.1." }}</span></h2>
<ol class="schedule__list">
{{- $seen := dict }}
{{- range sort .tours "time" }}
{{- range sort (.tours | default slice) "time" }}
{{- $nth := index $seen .time | default 0 }}
{{- $seen = merge $seen (dict .time (add $nth 1)) }}
{{- $page := $.Page.GetPage .tour }}
@ -84,7 +94,7 @@ so an hour without tours still gets a row.
{{- end }}
{{- /* Hour lines; where the first day has no tour in the hour's first row, its column shows the hour.
They sit in .schedule__days, whose first row holds the day titles, hence the + 1. */}}
{{- $firstDay := index $schedule.days 0 }}
{{- $firstDay := index $days 0 }}
{{- range $hours }}
{{- $row := .row }}
<div class="schedule__hour" style="--schedule-row: {{ add .row 1 }}" aria-hidden="true">
@ -95,3 +105,4 @@ They sit in .schedule__days, whose first row holds the day titles, hence the + 1
{{- end }}
</div>
</div>
{{- end }}