Use a list view on the desktop instead of calendar

| Desktop | Mobile |
| --- | --- |
| ![image](/attachments/5887a605-9fd8-42aa-bbdc-ea9259553eba) | ![image](/attachments/0b68bfa2-a3a7-4f7f-af46-e6217a07a586) |

Co-authored-by: stb <stb@noreply.git.hamburg.ccc.de>
Reviewed-on: #73
This commit is contained in:
Vincent Mahnke 2026-11-14 08:47:08 +01:00 • committed by stb
commit 3471d2487d
7 changed files with 277 additions and 65 deletions

View file

@ -114,10 +114,11 @@ days:
- `time` is `HH:MM` with a leading zero (`09:30`). Tours are sorted by time, so their order in the file doesn't matter. - `time` is `HH:MM` with a leading zero (`09:30`). Tours are sorted by time, so their order in the file doesn't matter.
- `title` (optional) replaces the page's title on the card, with one entry per language: `title: { de: "Hafen am Abend", en: "Harbour by Night" }`. - `title` (optional) replaces the page's title on the card, with one entry per language: `title: { de: "Hafen am Abend", en: "Harbour by Night" }`.
- `status` (optional): `soldout` marks the tour as fully booked. Other values are ignored. - `status` (optional): `soldout` marks the tour as fully booked. Other values are ignored.
- With JavaScript at viewport widths of at least 667px, the first local photo in the tour page fills the right 40% of its card behind a fade when it has alt text; its gallery credit remains visible.
For the events managed with Hackertours-Admin, the data file is generated by its website sync; don't edit it by hand. For the events managed with Hackertours-Admin, the data file is generated by its website sync; don't edit it by hand.
Wide screens get one column per day on an hour grid, with tours that start at the same time side by side. The first column shows the hour wherever the first day has no tour in it. On narrow screens a day picker shows one day at a time, starting with today's day during the event. With JavaScript, narrow screens show a day picker, starting with today's day during the event. Wider screens list days under their headings, hiding past days until the event ends. Before and after the event, all days are shown. Dates use the visitor's local time. Without JavaScript, narrow screens show all days stacked; wide screens show a column per day on an hour grid.
For a different event than the page's section, pass its name: `{{< schedule 39c3 >}}`. For a different event than the page's section, pass its name: `{{< schedule 39c3 >}}`.

75
tests/test_schedule.js Normal file
View file

@ -0,0 +1,75 @@
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const vm = require('node:vm');
const script = fs.readFileSync(
path.join(__dirname, '../themes/hackertours/assets/js/schedule.js'),
'utf8',
);
function runSchedule(today) {
const days = new Map();
const buttons = Array.from({ length: 5 }, (_, day) => {
const id = `day-${day}`;
const classes = new Set();
days.set(id, {
classes,
classList: {
toggle(name, enabled) {
if (enabled) classes.add(name);
else classes.delete(name);
},
},
});
return {
dataset: { date: `2026-12-${26 + day}` },
getAttribute: () => id,
setAttribute() {},
addEventListener(name, callback) {
this.click = callback;
},
};
});
const picker = { querySelectorAll: () => buttons, hidden: true };
const schedule = {
querySelector: () => picker,
classList: { add() {} },
};
const document = {
querySelectorAll: () => [schedule],
getElementById: (id) => days.get(id),
};
const Date = class {
toLocaleDateString() {
return today;
}
};
vm.runInNewContext(script, { document, Date });
return { buttons, days };
}
test('only past days are hidden during the event, and all return afterwards', () => {
const cases = [
['2026-12-25', []],
['2026-12-26', []],
['2026-12-28', [0, 1]],
['2026-12-30', [0, 1, 2, 3]],
['2026-12-31', []],
];
for (const [today, expected] of cases) {
const { days } = runSchedule(today);
const past = [...days.values()]
.map((day, index) => day.classes.has('schedule__day--past') ? index : null)
.filter((index) => index !== null);
assert.deepEqual(past, expected, today);
}
});
test('mobile selection can still switch to a past day', () => {
const { buttons, days } = runSchedule('2026-12-28');
buttons[0].click();
assert.ok(days.get('day-0').classes.has('schedule__day--selected'));
assert.ok(!days.get('day-2').classes.has('schedule__day--selected'));
});

View file

@ -1,4 +1,4 @@
/* Tour schedule shortcode: one column of cards per day, a day picker on narrow screens. */ /* Tour schedule shortcode: a mobile day picker and a wide-screen list, with a no-JavaScript grid fallback. */
.schedule { .schedule {
--schedule-line: color-mix(in oklch, var(--color-text) 20%, transparent); --schedule-line: color-mix(in oklch, var(--color-text) 20%, transparent);
@ -109,6 +109,7 @@
grid-template-columns: 1fr auto; grid-template-columns: 1fr auto;
gap: 0.15rem 0.5rem; gap: 0.15rem 0.5rem;
margin: 0; margin: 0;
max-width: none;
padding: 0.5rem 0.75rem 0.6rem; padding: 0.5rem 0.75rem 0.6rem;
border: 1px solid var(--schedule-line); border: 1px solid var(--schedule-line);
border-inline-start: 3px solid var(--schedule-accent); border-inline-start: 3px solid var(--schedule-accent);
@ -133,6 +134,59 @@
gap: 0 0.5rem; gap: 0 0.5rem;
} }
.schedule__photo {
display: none;
position: absolute;
inset: 0 0 0 60%;
z-index: -1;
margin: 0;
pointer-events: none;
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
mask-image: linear-gradient(90deg,
transparent 0%,
rgb(0 0 0 / 3%) 10%,
rgb(0 0 0 / 10%) 40%,
rgb(0 0 0 / 80%) 100%);
}
}
.schedule__photo-credit {
display: none;
grid-column: 1 / -1;
grid-row: 3;
font-size: var(--fs-xs);
color: var(--color-text-meta);
}
@media (width >= 667px) {
.schedule--picker .schedule__card--photo {
isolation: isolate;
overflow: hidden;
min-height: 7rem;
align-items: start;
.schedule__title,
.schedule__photo-credit {
max-width: 70%;
overflow-wrap: anywhere;
}
.schedule__lang {
background: var(--color-body-bg);
}
}
.schedule--picker .schedule__photo,
.schedule--picker .schedule__photo-credit {
display: block;
}
}
.schedule__status { .schedule__status {
font-family: var(--ff-alt); font-family: var(--ff-alt);
font-size: var(--fs-xs); font-size: var(--fs-xs);
@ -196,61 +250,61 @@
} }
} }
/* The picker only exists with JavaScript and is only used on narrow screens. */ /* The picker is only shown on mobile with JavaScript. */
.schedule__picker { .schedule__picker {
display: none; display: none;
} }
@container (width < 48rem) { /* Keeps a focused card from scrolling under the sticky day picker. */
/* Keeps a focused card from scrolling under the sticky day picker. */ .schedule__title {
.schedule__title { scroll-margin-block-start: 6rem;
scroll-margin-block-start: 6rem; }
}
.schedule__picker:not([hidden]) { .schedule__picker:not([hidden]) {
position: sticky; position: sticky;
inset-block-start: 0; inset-block-start: 0;
z-index: 2; z-index: 2;
display: flex; display: flex;
gap: 0.25rem; gap: 0.25rem;
margin-block-end: 1rem; margin-block-end: 1rem;
padding: 0.25rem; padding: 0.25rem;
border-radius: var(--radius-l); border-radius: var(--radius-l);
background: var(--color-body-bg); background: var(--color-body-bg);
box-shadow: inset 0 0 0 1px var(--schedule-line); box-shadow: inset 0 0 0 1px var(--schedule-line);
} }
.schedule__pick { .schedule__pick {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
padding: 0.35rem 0.25rem; padding: 0.35rem 0.25rem;
border: 0; border: 0;
border-radius: var(--radius-m); border-radius: var(--radius-m);
background: transparent; background: transparent;
color: var(--color-text); color: var(--color-text);
font-family: var(--ff-alt); font-family: var(--ff-alt);
font-size: var(--fs-s); font-size: var(--fs-s);
font-weight: bold; font-weight: bold;
cursor: pointer; cursor: pointer;
&[aria-pressed="true"] { &[aria-pressed="true"] {
background: var(--schedule-accent); background: var(--schedule-accent);
color: var(--color-body-bg); color: var(--color-body-bg);
.schedule__pick-date { .schedule__pick-date {
color: inherit; color: inherit;
}
} }
} }
}
.schedule__pick-date { .schedule__pick-date {
font-size: var(--fs-xs); font-size: var(--fs-xs);
font-weight: normal; font-weight: normal;
color: var(--color-text-meta); color: var(--color-text-meta);
} }
@media (width < 667px) {
.schedule--picker { .schedule--picker {
.schedule__day:not(.schedule__day--selected) { .schedule__day:not(.schedule__day--selected) {
display: none; display: none;
@ -267,3 +321,47 @@
} }
} }
} }
@container (width >= 48rem) {
.schedule--picker {
.schedule__days {
display: grid;
grid-template-columns: none;
grid-template-rows: none;
gap: var(--spacing-l);
}
.schedule__day {
display: block;
grid-column: auto;
grid-row: auto;
}
.schedule__list {
grid-template-rows: none;
}
.schedule__card {
grid-row: auto;
}
.schedule__title {
display: block;
-webkit-line-clamp: unset;
line-clamp: unset;
overflow: visible;
min-height: 0;
}
.schedule__hour {
display: none;
}
}
}
@media (width >= 667px) {
.schedule__picker:not([hidden]),
.schedule--picker .schedule__day--past {
display: none;
}
}

View file

@ -1,5 +1,4 @@
// Day picker for the schedule shortcode. The CSS only uses it on narrow screens; // Responsive schedule for the shortcode. Without JavaScript all days remain visible.
// without JavaScript all days stack vertically there.
for (const schedule of document.querySelectorAll('[data-schedule]')) { for (const schedule of document.querySelectorAll('[data-schedule]')) {
const picker = schedule.querySelector('.schedule__picker'); const picker = schedule.querySelector('.schedule__picker');
const buttons = [...picker.querySelectorAll('button')]; const buttons = [...picker.querySelectorAll('button')];
@ -22,6 +21,13 @@ for (const schedule of document.querySelectorAll('[data-schedule]')) {
const today = new Date().toLocaleDateString('sv'); const today = new Date().toLocaleDateString('sv');
select(buttons.find((button) => button.dataset.date === today) ?? buttons[0]); select(buttons.find((button) => button.dataset.date === today) ?? buttons[0]);
const hasUpcomingDays = buttons.some((button) => button.dataset.date >= today);
for (const button of buttons) {
document
.getElementById(button.getAttribute('aria-controls'))
.classList.toggle('schedule__day--past', hasUpcomingDays && button.dataset.date < today);
}
picker.hidden = false; picker.hidden = false;
schedule.classList.add('schedule--picker'); schedule.classList.add('schedule--picker');
} }

View file

@ -0,0 +1,19 @@
{{- $result := dict -}}
{{- with findRESubmatch `!\[([^\]]*)\]\(\s*<?([^\s)>]+)|\{\{<\s*gallery-image\s([^}]*)>\}\}` .RawContent 1 -}}
{{- $alt := index . 0 1 -}}
{{- $dest := index . 0 2 -}}
{{- $credit := "" -}}
{{- with index . 0 3 -}}
{{- $dest = "" -}}
{{- $alt = "" -}}
{{- with findRESubmatch "\\bsrc=(?:\"([^\"]*)\"|`([^`]*)`)" . 1 }}{{ $dest = or (index . 0 1) (index . 0 2) }}{{ end -}}
{{- with findRESubmatch "\\balt=(?:\"([^\"]*)\"|`([^`]*)`)" . 1 }}{{ $alt = or (index . 0 1) (index . 0 2) }}{{ end -}}
{{- with findRESubmatch "\\bcredit=(?:\"([^\"]*)\"|`([^`]*)`)" . 1 }}{{ $credit = or (index . 0 1) (index . 0 2) }}{{ end -}}
{{- end -}}
{{- $resource := false -}}
{{- if not (findRE `^https?://` $dest) -}}
{{- $resource = or ($.Resources.Get (strings.TrimPrefix "./" $dest)) (resources.Get $dest) -}}
{{- end -}}
{{- $result = dict "alt" $alt "credit" $credit "dest" $dest "resource" $resource -}}
{{- end -}}
{{- return $result -}}

View file

@ -6,24 +6,15 @@ gallery-image shortcode, scaled down to at most 1200 pixels wide, with its alt t
og:image:alt. og:image:alt.
*/ -}} */ -}}
{{- if not ($.Param "image") -}} {{- if not ($.Param "image") -}}
{{- /* Whichever comes first: a Markdown image or a gallery-image shortcode (src and alt in "…" or `…`). */ -}} {{- with partialCached "first-page-image.html" . .RelPermalink -}}
{{- with findRESubmatch `!\[([^\]]*)\]\(\s*<?([^\s)>]+)|\{\{<\s*gallery-image\s([^}]*)>\}\}` .RawContent 1 -}} {{- $alt := .alt -}}
{{- $alt := index . 0 1 -}} {{- $dest := .dest -}}
{{- $dest := index . 0 2 -}}
{{- with index . 0 3 -}}
{{- $dest = "" -}}
{{- $alt = "" -}}
{{- with findRESubmatch "\\bsrc=(?:\"([^\"]*)\"|`([^`]*)`)" . 1 }}{{ $dest = or (index . 0 1) (index . 0 2) }}{{ end -}}
{{- with findRESubmatch "\\balt=(?:\"([^\"]*)\"|`([^`]*)`)" . 1 }}{{ $alt = or (index . 0 1) (index . 0 2) }}{{ end -}}
{{- end -}}
{{- $url := "" -}} {{- $url := "" -}}
{{- $width := 0 -}} {{- $width := 0 -}}
{{- $height := 0 -}} {{- $height := 0 -}}
{{- $resource := false -}} {{- $resource := .resource -}}
{{- if findRE `^https?://` $dest -}} {{- if findRE `^https?://` $dest -}}
{{- $url = $dest -}} {{- $url = $dest -}}
{{- else -}}
{{- $resource = or ($.Resources.Get (strings.TrimPrefix "./" $dest)) (resources.Get $dest) -}}
{{- end -}} {{- end -}}
{{- with $resource -}} {{- with $resource -}}
{{- $image := . -}} {{- $image := . -}}

View file

@ -1,6 +1,6 @@
{{- /* {{- /*
Tour schedule from data/schedule/<event>.yaml, one column of tour cards per day. Tour schedule from data/schedule/<event>.yaml.
On narrow screens the days stack; with JavaScript a day picker shows one day at a time. With JavaScript a day picker shows one day at a time; without it all days are visible.
Usage: {{< schedule >}} on a section page (the event is the section name), Usage: {{< schedule >}} on a section page (the event is the section name),
or {{< schedule 39c3 >}}. or {{< schedule 39c3 >}}.
@ -81,7 +81,23 @@ so an hour without tours still gets a row.
{{- /* A tour's own title, in the page's language, replaces its page's title. */}} {{- /* A tour's own title, in the page's language, replaces its page's title. */}}
{{- $ownTitle := "" }} {{- $ownTitle := "" }}
{{- with .title }}{{ $ownTitle = index . site.Language.Name | default (index . "en") }}{{ end }} {{- with .title }}{{ $ownTitle = index . site.Language.Name | default (index . "en") }}{{ end }}
<li class="schedule__card{{ if $soldOut }} schedule__card--soldout{{ end }}" style="--schedule-row: {{ add (index $slotRow .time) $nth }}"> {{- $photo := false }}
{{- $photoAlt := "" }}
{{- $photoCredit := "" }}
{{- with $page }}
{{- with partialCached "first-page-image.html" . .RelPermalink }}
{{- if and .resource .alt }}
{{- if and (eq .resource.ResourceType "image") (ne .resource.MediaType.SubType "svg") }}
{{- $oriented := .resource.Filter images.AutoOrient }}
{{- $photo = $oriented }}
{{- if gt $oriented.Width 1600 }}{{ $photo = $oriented.Resize "1600x" }}{{ end }}
{{- $photoAlt = .alt }}
{{- $photoCredit = .credit }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
<li class="schedule__card{{ if $soldOut }} schedule__card--soldout{{ end }}{{ if $photo }} schedule__card--photo{{ end }}" style="--schedule-row: {{ add (index $slotRow .time) $nth }}">
<span class="schedule__when"> <span class="schedule__when">
<time class="schedule__time" datetime="{{ $day.date }}T{{ .time }}">{{ .time }}</time> <time class="schedule__time" datetime="{{ $day.date }}T{{ .time }}">{{ .time }}</time>
{{- if $soldOut }} {{- if $soldOut }}
@ -97,6 +113,12 @@ so an hour without tours still gets a row.
{{- else }} {{- else }}
<span class="schedule__title">{{ $ownTitle | default $entry.tour }}</span> <span class="schedule__title">{{ $ownTitle | default $entry.tour }}</span>
{{- end }} {{- end }}
{{- with $photo }}
<figure class="schedule__photo">
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="{{ $photoAlt }}" loading="lazy" decoding="async">
</figure>
{{- with $photoCredit }}<span class="schedule__photo-credit">{{ . }}</span>{{ end }}
{{- end }}
</li> </li>
{{- end }} {{- end }}
</ol> </ol>