diff --git a/README.md b/README.md index 2791f61..ad41192 100644 --- a/README.md +++ b/README.md @@ -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. - `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. +- 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. -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 >}}`. diff --git a/tests/test_schedule.js b/tests/test_schedule.js new file mode 100644 index 0000000..28dd716 --- /dev/null +++ b/tests/test_schedule.js @@ -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')); +}); diff --git a/themes/hackertours/assets/css/_schedule.css b/themes/hackertours/assets/css/_schedule.css index d91766b..7757cfc 100644 --- a/themes/hackertours/assets/css/_schedule.css +++ b/themes/hackertours/assets/css/_schedule.css @@ -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-line: color-mix(in oklch, var(--color-text) 20%, transparent); @@ -109,6 +109,7 @@ grid-template-columns: 1fr auto; gap: 0.15rem 0.5rem; margin: 0; + max-width: none; padding: 0.5rem 0.75rem 0.6rem; border: 1px solid var(--schedule-line); border-inline-start: 3px solid var(--schedule-accent); @@ -133,6 +134,59 @@ 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 { font-family: var(--ff-alt); 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 { display: none; } -@container (width < 48rem) { - /* Keeps a focused card from scrolling under the sticky day picker. */ - .schedule__title { - scroll-margin-block-start: 6rem; - } +/* Keeps a focused card from scrolling under the sticky day picker. */ +.schedule__title { + scroll-margin-block-start: 6rem; +} - .schedule__picker:not([hidden]) { - position: sticky; - inset-block-start: 0; - z-index: 2; - display: flex; - gap: 0.25rem; - margin-block-end: 1rem; - padding: 0.25rem; - border-radius: var(--radius-l); - background: var(--color-body-bg); - box-shadow: inset 0 0 0 1px var(--schedule-line); - } +.schedule__picker:not([hidden]) { + position: sticky; + inset-block-start: 0; + z-index: 2; + display: flex; + gap: 0.25rem; + margin-block-end: 1rem; + padding: 0.25rem; + border-radius: var(--radius-l); + background: var(--color-body-bg); + box-shadow: inset 0 0 0 1px var(--schedule-line); +} - .schedule__pick { - flex: 1; - display: flex; - flex-direction: column; - align-items: center; - padding: 0.35rem 0.25rem; - border: 0; - border-radius: var(--radius-m); - background: transparent; - color: var(--color-text); - font-family: var(--ff-alt); - font-size: var(--fs-s); - font-weight: bold; - cursor: pointer; +.schedule__pick { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + padding: 0.35rem 0.25rem; + border: 0; + border-radius: var(--radius-m); + background: transparent; + color: var(--color-text); + font-family: var(--ff-alt); + font-size: var(--fs-s); + font-weight: bold; + cursor: pointer; - &[aria-pressed="true"] { - background: var(--schedule-accent); - color: var(--color-body-bg); + &[aria-pressed="true"] { + background: var(--schedule-accent); + color: var(--color-body-bg); - .schedule__pick-date { - color: inherit; - } + .schedule__pick-date { + color: inherit; } } +} - .schedule__pick-date { - font-size: var(--fs-xs); - font-weight: normal; - color: var(--color-text-meta); - } +.schedule__pick-date { + font-size: var(--fs-xs); + font-weight: normal; + color: var(--color-text-meta); +} +@media (width < 667px) { .schedule--picker { .schedule__day:not(.schedule__day--selected) { 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; + } +} diff --git a/themes/hackertours/assets/js/schedule.js b/themes/hackertours/assets/js/schedule.js index 05bd15f..9ce06a6 100644 --- a/themes/hackertours/assets/js/schedule.js +++ b/themes/hackertours/assets/js/schedule.js @@ -1,5 +1,4 @@ -// Day picker for the schedule shortcode. The CSS only uses it on narrow screens; -// without JavaScript all days stack vertically there. +// Responsive schedule for the shortcode. Without JavaScript all days remain visible. for (const schedule of document.querySelectorAll('[data-schedule]')) { const picker = schedule.querySelector('.schedule__picker'); const buttons = [...picker.querySelectorAll('button')]; @@ -22,6 +21,13 @@ for (const schedule of document.querySelectorAll('[data-schedule]')) { const today = new Date().toLocaleDateString('sv'); 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; schedule.classList.add('schedule--picker'); } diff --git a/themes/hackertours/layouts/_partials/first-page-image.html b/themes/hackertours/layouts/_partials/first-page-image.html new file mode 100644 index 0000000..5225aa8 --- /dev/null +++ b/themes/hackertours/layouts/_partials/first-page-image.html @@ -0,0 +1,19 @@ +{{- $result := dict -}} +{{- with findRESubmatch `!\[([^\]]*)\]\(\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 -}} diff --git a/themes/hackertours/layouts/_partials/head/extra.html b/themes/hackertours/layouts/_partials/head/extra.html index 74fd6b7..6bedff0 100644 --- a/themes/hackertours/layouts/_partials/head/extra.html +++ b/themes/hackertours/layouts/_partials/head/extra.html @@ -6,24 +6,15 @@ gallery-image shortcode, scaled down to at most 1200 pixels wide, with its alt t og:image:alt. */ -}} {{- if not ($.Param "image") -}} - {{- /* Whichever comes first: a Markdown image or a gallery-image shortcode (src and alt in "…" or `…`). */ -}} - {{- with findRESubmatch `!\[([^\]]*)\]\(\s*]+)|\{\{<\s*gallery-image\s([^}]*)>\}\}` .RawContent 1 -}} - {{- $alt := index . 0 1 -}} - {{- $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 -}} + {{- with partialCached "first-page-image.html" . .RelPermalink -}} + {{- $alt := .alt -}} + {{- $dest := .dest -}} {{- $url := "" -}} {{- $width := 0 -}} {{- $height := 0 -}} - {{- $resource := false -}} + {{- $resource := .resource -}} {{- if findRE `^https?://` $dest -}} {{- $url = $dest -}} - {{- else -}} - {{- $resource = or ($.Resources.Get (strings.TrimPrefix "./" $dest)) (resources.Get $dest) -}} {{- end -}} {{- with $resource -}} {{- $image := . -}} diff --git a/themes/hackertours/layouts/_shortcodes/schedule.html b/themes/hackertours/layouts/_shortcodes/schedule.html index ed4c9f1..226cb5e 100644 --- a/themes/hackertours/layouts/_shortcodes/schedule.html +++ b/themes/hackertours/layouts/_shortcodes/schedule.html @@ -1,6 +1,6 @@ {{- /* -Tour schedule from data/schedule/.yaml, one column of tour cards per day. -On narrow screens the days stack; with JavaScript a day picker shows one day at a time. +Tour schedule from data/schedule/.yaml. +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), 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. */}} {{- $ownTitle := "" }} {{- with .title }}{{ $ownTitle = index . site.Language.Name | default (index . "en") }}{{ end }} -
  • +{{- $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 }} +
  • {{- if $soldOut }} @@ -97,6 +113,12 @@ so an hour without tours still gets a row. {{- else }} {{ $ownTitle | default $entry.tour }} {{- end }} +{{- with $photo }} +
    +{{ $photoAlt }} +
    +{{- with $photoCredit }}{{ . }}{{ end }} +{{- end }}
  • {{- end }}