@sarimarcus/content-sites-tourism 0.74.1 → 0.74.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All packages in the platform release in lockstep; entries are per release version.
4
4
 
5
+ ## 0.74.2 (2026-11-17)
6
+
7
+ Additive (SLA-4223). No codemod; nothing changes until a site renders the new template or passes the nav entry.
8
+
9
+ - `TourismWhatsOnPage` and `buildWhatsOnModel` (`./templates`): the /whats-on timetable from an agenda snapshot (brief: `docs/design-briefs/whats-on.md`, direction B). Run chips for multi-day items under way, contiguous windows from today (this weekend, next weekend, later in the month) with a day numeral per day, regular fixtures on a thin week (`fallback`, or a weekend overlapped by fewer than `minCount` dated items, default 3), an optional `months` band (`MonthStripNav`), and slots `after-window-1` / `after-window-2` for the affiliate strips. An inline script hides what ended since the build. The model's `items` is the page order for core's `agendaItemListBuilder`; the template emits no JSON-LD. Styles are `.wo-*` rules in `home.css`.
10
+ - `TourismNavigation`: optional `events.whatsOn` link in the Events dropdown and mobile section; off unless the site passes it (output unchanged otherwise).
11
+ - Fixture `fixture/agenda-snapshot.json` (checked against core's `agendaSnapshotIssues`) and unit tests `tests/whats-on-model.test.mjs`. Proof: 6 sites, astro check 0 errors, html identical on every page; the only difference is the added `.wo-*` CSS rules in the shared stylesheet (`<site>=css:added` on the four sites that load `home.css`).
12
+
5
13
  ## 0.74.1 (2026-11-16)
6
14
 
7
15
  Patch (SLA-4247). No codemod.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarimarcus/content-sites-tourism",
3
- "version": "0.74.1",
3
+ "version": "0.74.2",
4
4
  "description": "City-tourism vertical: city-entity components, pages templates and utilities for the tourism sites.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "astro": "^7.0.6",
42
42
  "tailwindcss": "^4.1.18",
43
- "@sarimarcus/content-sites-core": "0.74.1",
44
- "@sarimarcus/content-sites-ui": "0.74.1"
43
+ "@sarimarcus/content-sites-core": "0.74.2",
44
+ "@sarimarcus/content-sites-ui": "0.74.2"
45
45
  }
46
46
  }
@@ -23,7 +23,7 @@ const exploreActive = anyOn(explore.links) || on(explore.allGuides.href) || on(e
23
23
  const eatDrinkActive = anyOn(eatDrink.links);
24
24
  const planActive = anyOn(plan.links) || on(plan.hub.href);
25
25
  const itinerariesActive = itineraries.durations.some((d) => on(d.href)) || anyOn(itineraries.connections) || on(itineraries.all.href);
26
- const eventsActive = anyOn(events.upcoming) || anyOn(events.guides) || on(events.all.href);
26
+ const eventsActive = anyOn(events.upcoming) || anyOn(events.guides) || on(events.all.href) || (events.whatsOn ? on(events.whatsOn.href) : false);
27
27
 
28
28
  const panel = 'bg-card rounded-xl border border-border shadow-xl shadow-foreground/10 overflow-hidden';
29
29
  const heading = 'text-xs font-semibold text-muted-foreground uppercase tracking-wide';
@@ -142,7 +142,7 @@ const monthTone = (m: { current?: boolean; peak?: boolean }, hover: boolean) =>
142
142
  {events.guides.map((link) => <NavMenuLink link={link} tone="accent" size="sm" active={on(link.href)} />)}
143
143
  </div>
144
144
  <div class="border-t border-border p-2">
145
- <NavMenuLink link={events.all} tone="accent" align="center" active={on(events.all.href)} />
145
+ {events.whatsOn && <NavMenuLink link={events.whatsOn} tone="accent" align="center" active={on(events.whatsOn.href)} />}<NavMenuLink link={events.all} tone="accent" align="center" active={on(events.all.href)} />
146
146
  </div>
147
147
  </div>
148
148
  </NavDropdown>
@@ -216,7 +216,7 @@ const monthTone = (m: { current?: boolean; peak?: boolean }, hover: boolean) =>
216
216
  )}
217
217
  <div class={`px-4 pt-2 pb-1 ${heading}`}>{events.guidesHeading}</div>
218
218
  {events.guides.map((link) => <MobileNavLink link={link} tone="accent" active={on(link.href)} />)}
219
- <MobileNavLink link={events.all} tone="accent" iconStrong active={on(events.all.href)} />
219
+ {events.whatsOn && <MobileNavLink link={events.whatsOn} tone="accent" iconStrong active={on(events.whatsOn.href)} />}<MobileNavLink link={events.all} tone="accent" iconStrong active={on(events.all.href)} />
220
220
  </MobileNavSection>
221
221
 
222
222
  <div class="pointer-events-none sticky bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-background via-background/50 to-transparent mobile-scroll-fade"></div>
@@ -41,7 +41,8 @@ export interface TourismNavigationProps {
41
41
  connectionsHeading: string;
42
42
  connections: NavLink[];
43
43
  };
44
- events: Group & { upcomingHeading: string; upcoming: NavLink[]; guidesHeading: string; guides: NavLink[]; all: NavLink };
44
+ /** `whatsOn`: the /whats-on hub. Off by default; a site turns it on by passing it. */
45
+ events: Group & { upcomingHeading: string; upcoming: NavLink[]; guidesHeading: string; guides: NavLink[]; all: NavLink; whatsOn?: NavLink };
45
46
  search: { href: string; label: string; text: string; mobileLabel: string; path: string };
46
47
  }
47
48
 
@@ -0,0 +1,129 @@
1
+ ---
2
+ /**
3
+ * TourismWhatsOnPage — the /whats-on timetable (SLA-4223, brief: docs/design-briefs/whats-on.md). Slots
4
+ * `after-window-1` and `after-window-2` take the affiliate strips between windows. Styles live in home.css.
5
+ */
6
+ import { Container } from '@sarimarcus/content-sites-ui/layout';
7
+ import { Badge } from '@sarimarcus/content-sites-ui/primitives';
8
+ import MonthStripNav from './MonthStripNav.astro';
9
+ import type { WhatsOnModel } from './whatsOnModel.ts';
10
+
11
+ interface Props { model: WhatsOnModel }
12
+ const { model } = Astro.props;
13
+ const { head, checked, labels, runs, windows, regulars, months } = model;
14
+ const rel = (external: boolean) => (external ? 'noopener' : undefined);
15
+ const slotAfter = ['after-window-1', 'after-window-2'].map((name) => (Astro.slots.has(name) ? name : undefined));
16
+ ---
17
+ <main class="hp wo" data-whats-on data-tz={model.timezone}>
18
+ <section class="hp-lead wo-lead" aria-labelledby="wo-h1" data-track-zone="hero">
19
+ <Container>
20
+ <h1 id="wo-h1">{head.heading}</h1>
21
+ <p class="hp-lead__stand">{head.standfirst}</p>
22
+ <p class="hp-meta wo-checked"><time datetime={checked.datetime}>{checked.label}</time></p>
23
+ </Container>
24
+ </section>
25
+
26
+ {runs && (
27
+ <section class="hp-band hp-band--muted wo-runs" aria-labelledby="wo-runs-h" data-track-zone="runs">
28
+ <Container>
29
+ <h2 id="wo-runs-h" class="wo-runs__h">{runs.heading}</h2>
30
+ <ul role="list" class="wo-chips">
31
+ {runs.items.map((r) => (
32
+ <li data-ends={r.endsOn}>
33
+ <a href={r.href} rel={rel(r.external)}>{r.title}</a>
34
+ <span class="hp-meta">{r.span} · {r.venue}</span>
35
+ </li>
36
+ ))}
37
+ </ul>
38
+ </Container>
39
+ </section>
40
+ )}
41
+
42
+ {windows.map((w, i) => (
43
+ <>
44
+ <section class="hp-band wo-window" id={w.id} aria-labelledby={`${w.id}-h`} data-track-zone={w.id}>
45
+ <Container>
46
+ <h2 id={`${w.id}-h`} class="wo-band"><span>{w.heading}</span> <span class="hp-meta">{w.range}</span></h2>
47
+ <p class="wo-empty" hidden={w.days.length > 0}>{w.empty}</p>
48
+ {w.days.length > 0 && (
49
+ <ol role="list" class="wo-days">
50
+ {w.days.map((d) => (
51
+ <li class="wo-day" data-day={d.day}>
52
+ <p class="wo-day__num"><span class="wo-day__wd">{d.weekday}</span><span class="wo-day__d">{d.numeral}</span><span class="wo-day__m">{d.month}</span></p>
53
+ <ul role="list" class="wo-rows">
54
+ {d.rows.map((r) => (
55
+ <li class:list={['wo-row', { 'is-lead': r.lead }]} data-ends={r.endsOn} data-key={r.id}>
56
+ <span class="wo-row__time">{r.time ?? ''}</span>
57
+ <div class="wo-row__main">
58
+ <h3><a href={r.href} rel={rel(r.external)}>{r.title}</a></h3>
59
+ {r.lead && <span class="wo-pick">{labels.pick}</span>}
60
+ {r.until && <span class="hp-meta wo-until">{r.until}</span>}
61
+ {r.blurb && <p class="wo-row__blurb">{r.blurb}</p>}
62
+ </div>
63
+ <div class="wo-row__meta">
64
+ <p class="wo-row__venue">
65
+ {r.venue.href ? <a class="hp-quiet" href={r.venue.href}><span class="sr-only">{labels.venue}: </span>{r.venue.name}</a> : <span>{r.venue.name}</span>}
66
+ </p>
67
+ <p class="wo-row__price">
68
+ {r.free && <Badge tone="outline" size="sm" lines={0}>{labels.free}</Badge>}
69
+ {r.sourceHref && <a href={r.sourceHref} rel="noopener">{labels.source}</a>}
70
+ {r.ticketsHref && <a href={r.ticketsHref} rel="noopener">{labels.tickets}{r.price ? ` · ${r.price}` : ''}</a>}
71
+ </p>
72
+ </div>
73
+ </li>
74
+ ))}
75
+ </ul>
76
+ </li>
77
+ ))}
78
+ </ol>
79
+ )}
80
+ </Container>
81
+ </section>
82
+ {slotAfter[i] && <div class="hp-embed" data-track-zone={slotAfter[i]}><slot name={slotAfter[i]} /></div>}
83
+ </>
84
+ ))}
85
+
86
+ {regulars && (
87
+ <section class="hp-band hp-band--muted wo-regulars" aria-labelledby="wo-reg-h" data-track-zone="regulars">
88
+ <Container>
89
+ <div class="hp-head">
90
+ <h2 id="wo-reg-h">{regulars.heading}</h2>
91
+ <p>{regulars.intro}</p>
92
+ </div>
93
+ <ul role="list" class="wo-reg">
94
+ {regulars.items.map((r) => (
95
+ <li data-ends={r.endsOn}>
96
+ <h3><a href={r.href} rel={rel(r.external)}>{r.title}</a></h3>
97
+ <p class="hp-meta">{r.recurrence ? `${r.recurrence} · ` : ''}{r.venue}</p>
98
+ </li>
99
+ ))}
100
+ </ul>
101
+ </Container>
102
+ </section>
103
+ )}
104
+
105
+ {months && (
106
+ <section class="hp-band wo-months" aria-labelledby="wo-months-h" data-track-zone="months">
107
+ <Container>
108
+ <h2 id="wo-months-h" class="wo-band">{months.heading}</h2>
109
+ <MonthStripNav strip={months.strip} />
110
+ </Container>
111
+ </section>
112
+ )}
113
+ </main>
114
+
115
+ <script is:inline>
116
+ // The site is static: hide items that ended after the build. Without JS the build-time filter stands.
117
+ (() => {
118
+ const root = document.querySelector('[data-whats-on]');
119
+ if (!root) return;
120
+ const today = new Intl.DateTimeFormat('en-CA', { timeZone: root.dataset.tz, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date());
121
+ root.querySelectorAll('[data-ends]').forEach((el) => { if (el.dataset.ends < today) el.hidden = true; });
122
+ root.querySelectorAll('.wo-day').forEach((d) => { if (!d.querySelector('.wo-row:not([hidden])')) d.hidden = true; });
123
+ root.querySelectorAll('.wo-window').forEach((w) => {
124
+ const list = w.querySelector('.wo-days');
125
+ if (list && !list.querySelector('.wo-day:not([hidden])')) { list.hidden = true; w.querySelector('.wo-empty').hidden = false; }
126
+ });
127
+ root.querySelectorAll('.wo-runs, .wo-regulars').forEach((s) => { if (!s.querySelector('li:not([hidden])')) s.hidden = true; });
128
+ })();
129
+ </script>
@@ -396,3 +396,42 @@
396
396
 
397
397
  /* a grid item stretches to the row; keep the glyphs on the title's first line */
398
398
  .hp .hp-rank .hp-mark { align-self: start; }
399
+
400
+ /* What's on: day-by-day timetable (SLA-4223) */
401
+ .hp.wo [hidden] { display: none !important; }
402
+ .hp :is(.wo-row__main h3, .wo-reg h3) a, .hp :is(.wo-row__venue, .wo-row__price, .wo-chips) a { display: inline-flex; align-items: center; min-width: 2.75rem; min-height: 2.75rem; }
403
+ .hp .wo-lead { padding-bottom: 1.5rem; }
404
+ .hp .wo-checked { margin-top: 0.75rem; }
405
+ .hp .wo-band { position: sticky; top: var(--wo-sticky, var(--site-header-offset, 4rem)); z-index: 2; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; margin: 0 0 1rem; padding-block: 0.625rem; background: var(--background); border-bottom: var(--hp-rule); font-size: 1.25rem; }
406
+ .hp .wo-window { padding-block: clamp(1.5rem, 3vw, 2.5rem); }
407
+ .hp .wo-empty { color: var(--muted-foreground); }
408
+ .hp .wo-chips { display: grid; gap: 0.5rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
409
+ .hp .wo-chips li { display: grid; gap: 0.125rem; padding-block: 0.5rem; border-top: var(--hp-rule); }
410
+ .hp .wo-runs__h { font-size: 1rem; margin-bottom: 0.75rem; }
411
+ .hp .wo-days { display: grid; gap: 0; }
412
+ .hp .wo-day { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr); gap: 0 1rem; padding-block: 1rem; border-bottom: var(--hp-rule); }
413
+ .hp .wo-day__num { display: grid; justify-items: center; align-content: start; line-height: 1; font-variant-numeric: tabular-nums; }
414
+ .hp .wo-day__wd, .hp .wo-day__m { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-foreground); }
415
+ .hp .wo-day__d { font-family: var(--font-display); font-size: 2rem; margin-block: 0.125rem; }
416
+ .hp .wo-rows { display: grid; gap: 0.875rem; }
417
+ .hp .wo-row { display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); gap: 0.125rem 0.75rem; font-variant-numeric: tabular-nums; }
418
+ .hp .wo-row__time { grid-row: 1 / span 2; display: flex; align-items: center; align-self: start; min-height: 2.75rem; color: var(--muted-foreground); font-size: 0.9375rem; }
419
+ .hp .wo-row__main, .hp .wo-row__meta { grid-column: 2; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; column-gap: 0.625rem; }
420
+ .hp .wo-row__meta { column-gap: 1rem; }
421
+ .hp .wo-row__venue, .hp .wo-row__price { font-size: 0.9375rem; color: var(--muted-foreground); }
422
+ .hp .wo-row__price:empty { display: none; }
423
+ .hp .wo-row__price { display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.75rem; }
424
+ .hp .wo-row__main h3 { font-size: 1.0625rem; }
425
+ .hp .wo-row__blurb { flex-basis: 100%; max-width: 40rem; margin-bottom: 0.25rem; color: var(--foreground); font-size: 0.9375rem; }
426
+ .hp .wo-pick { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary-strong); }
427
+ .hp .wo-reg { display: grid; gap: 1rem 2rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
428
+ .hp .wo-reg li { padding-top: 0.75rem; border-top: var(--hp-rule); }
429
+ @media (min-width: 52rem) {
430
+ .hp .wo-day { grid-template-columns: 5rem minmax(0, 1fr); }
431
+ .hp .wo-row { grid-template-columns: 4rem minmax(0, 1fr) minmax(0, 14rem) 9rem; align-items: start; gap: 0 1rem; }
432
+ .hp .wo-row__time { grid-row: auto; }
433
+ .hp .wo-row__main { grid-column: auto; }
434
+ .hp .wo-row__meta { display: contents; }
435
+ .hp .wo-row__venue, .hp .wo-row__price { display: flex; align-items: center; min-height: 2.75rem; }
436
+ .hp .wo-row__price { justify-content: flex-end; }
437
+ }
@@ -18,3 +18,6 @@ export type { DetailBodyContent, DetailBodySection, TocItem } from './detailBody
18
18
  export { default as TourismHomePage } from './TourismHomePage.astro';
19
19
  export { formatSpan, eventName, eventPlace, eventEntry, selectHomeEvents, handLinkedHrefs, countWord } from './tourismHomeModel.ts';
20
20
  export type * from './tourismHomeModel.ts';
21
+ export { default as TourismWhatsOnPage } from './TourismWhatsOnPage.astro';
22
+ export { buildWhatsOnModel, shortDay } from './whatsOnModel.ts';
23
+ export type * from './whatsOnModel.ts';
@@ -0,0 +1,180 @@
1
+ import type { AgendaItem } from '@sarimarcus/content-sites-core/schema';
2
+ import { agendaDay, addDays, formatUtcDate, isExpired, overlapsWindow } from '@sarimarcus/content-sites-core/dates';
3
+ import type { AgendaWindows, DayWindow } from '@sarimarcus/content-sites-core/dates';
4
+ import type { MonthStrip } from './tourismMonthGuideModel.ts';
5
+
6
+ /** One timetable row. Everything arrives formatted; the template never computes. */
7
+ export interface WhatsOnRow {
8
+ id: string;
9
+ title: string;
10
+ /** `/event/<slug>` or the venue page, else the official source (`external`). */
11
+ href: string;
12
+ external: boolean;
13
+ /** "20:00", only when the source gives a time. */
14
+ time?: string;
15
+ venue: { name: string; href?: string };
16
+ free: boolean;
17
+ /** "from €12". */
18
+ price?: string;
19
+ ticketsHref?: string;
20
+ /** The official listing of a free item whose title links to a site page. */
21
+ sourceHref?: string;
22
+ /** The lead row's blurb, or the teaser of an item whose `/event/` page owns the detail. */
23
+ blurb?: string;
24
+ lead: boolean;
25
+ /** Last day, ISO: the inline script hides the row once it is past. */
26
+ endsOn: string;
27
+ /** "until 2 Dec", for a multi-day item listed on its start day. */
28
+ until?: string;
29
+ }
30
+
31
+ export interface WhatsOnDay { day: string; weekday: string; numeral: string; month: string; rows: WhatsOnRow[] }
32
+
33
+ export interface WhatsOnWindow { id: string; heading: string; range: string; days: WhatsOnDay[]; empty: string }
34
+
35
+ /** A multi-day item already under way, shown once with its span. */
36
+ export interface WhatsOnRun { id: string; title: string; href: string; external: boolean; span: string; venue: string; endsOn: string }
37
+
38
+ /** A recurring item of the thin-week fallback. */
39
+ export interface WhatsOnRegular { id: string; title: string; href: string; external: boolean; recurrence: string; venue: string; endsOn?: string }
40
+
41
+ export interface WhatsOnLabels {
42
+ pick: string;
43
+ free: string;
44
+ tickets: string;
45
+ /** Template with `{n}`: "from €{n}". */
46
+ from: string;
47
+ /** Template with `{day}`: "until {day}". */
48
+ until: string;
49
+ /** Screen-reader prefix of a row's venue link, e.g. "Venue". */
50
+ venue: string;
51
+ /** Link to the official listing of a free item, e.g. "Official listing". */
52
+ source: string;
53
+ }
54
+
55
+ export interface WhatsOnModel {
56
+ head: { heading: string; standfirst: string };
57
+ /** "Checked 16 Nov": `datetime` is the snapshot's `generatedAt` day. */
58
+ checked: { label: string; datetime: string };
59
+ labels: WhatsOnLabels;
60
+ /** IANA zone the inline expiry script reads "today" in. */
61
+ timezone: string;
62
+ runs?: { heading: string; items: WhatsOnRun[] };
63
+ windows: WhatsOnWindow[];
64
+ regulars?: { heading: string; intro: string; items: WhatsOnRegular[] };
65
+ /** Month guides for the visitor planning further ahead, through `MonthStripNav`. */
66
+ months?: { heading: string; strip: MonthStrip };
67
+ }
68
+
69
+ export interface WhatsOnBuildOptions {
70
+ items: AgendaItem[];
71
+ windows: AgendaWindows;
72
+ fallback: boolean;
73
+ /** A weekend overlapped by fewer dated items also brings in the regular fixtures. Default 3. */
74
+ minCount?: number;
75
+ labels: WhatsOnLabels;
76
+ /** `thisWeek`/`nextWeek` replace the weekend headings when their window also holds weekdays. */
77
+ headings: { thisWeekend: string; nextWeekend: string; later: string; runs: string; regulars: string; thisWeek?: string; nextWeek?: string };
78
+ empty: string;
79
+ regularsIntro: string;
80
+ locale?: string;
81
+ }
82
+
83
+ /** `2026-11-21` → "21 Nov". */
84
+ export function shortDay(day: string, locale = 'en-GB'): string {
85
+ return formatUtcDate(day, { day: 'numeric', month: 'short' }, locale);
86
+ }
87
+
88
+ const rangeLabel = (w: DayWindow, locale: string) => (w.start === w.end ? shortDay(w.start, locale) : `${shortDay(w.start, locale)} – ${shortDay(w.end, locale)}`);
89
+
90
+ const startDay = (it: AgendaItem) => agendaDay(it.startDate);
91
+ const lastDay = (it: AgendaItem) => it.endDate ?? startDay(it);
92
+ const timeOf = (it: AgendaItem) => (it.startDate.length > 10 ? it.startDate.slice(11, 16) : undefined);
93
+ const within = (w: DayWindow) => (it: AgendaItem) => startDay(it) >= w.start && startDay(it) <= w.end;
94
+ const byStart = (a: AgendaItem, b: AgendaItem) => a.startDate.localeCompare(b.startDate) || a.title.localeCompare(b.title);
95
+
96
+ function target(it: AgendaItem): { href: string; external: boolean } {
97
+ const href = it.href ?? it.venue.href;
98
+ return href ? { href, external: false } : { href: it.sourceUrl, external: true };
99
+ }
100
+
101
+ function toRow(it: AgendaItem, o: WhatsOnBuildOptions, locale: string, lead: boolean): WhatsOnRow {
102
+ const free = it.free === true;
103
+ const last = lastDay(it);
104
+ const link = target(it);
105
+ return {
106
+ id: it.id,
107
+ title: it.title,
108
+ ...link,
109
+ time: timeOf(it),
110
+ venue: { name: it.venue.name, href: it.venue.href },
111
+ free,
112
+ price: !free && it.priceFrom !== undefined && it.priceFrom > 0 ? o.labels.from.replace('{n}', String(it.priceFrom)) : undefined,
113
+ ticketsHref: free ? undefined : it.sourceUrl,
114
+ sourceHref: free && !link.external ? it.sourceUrl : undefined,
115
+ blurb: lead || it.href?.startsWith('/event/') ? it.blurb : undefined,
116
+ lead,
117
+ endsOn: last,
118
+ until: last > startDay(it) ? o.labels.until.replace('{day}', shortDay(last, locale)) : undefined,
119
+ };
120
+ }
121
+
122
+ /** `items` arrive sorted by start. */
123
+ function groupByDay(items: AgendaItem[], o: WhatsOnBuildOptions, locale: string): WhatsOnDay[] {
124
+ const leadId = items.find((i) => i.lead)?.id;
125
+ const days = new Map<string, WhatsOnDay>();
126
+ for (const it of items) {
127
+ const day = startDay(it);
128
+ if (!days.has(day)) {
129
+ days.set(day, {
130
+ day,
131
+ weekday: formatUtcDate(day, { weekday: 'short' }, locale),
132
+ numeral: String(Number(day.slice(8))),
133
+ month: formatUtcDate(day, { month: 'short' }, locale),
134
+ rows: [],
135
+ });
136
+ }
137
+ days.get(day)!.rows.push(toRow(it, o, locale, it.id === leadId));
138
+ }
139
+ return [...days.values()];
140
+ }
141
+
142
+ /**
143
+ * Windows are contiguous from today, so no dated item falls between them. States: docs/design-briefs/whats-on.md.
144
+ * `items` is what the page shows, in page order, for core's `agendaItemListBuilder`.
145
+ */
146
+ export function buildWhatsOnModel(o: WhatsOnBuildOptions): Pick<WhatsOnModel, 'runs' | 'windows' | 'regulars'> & { items: AgendaItem[] } {
147
+ const locale = o.locale ?? 'en-GB';
148
+ const { today, thisWeekend, nextWeekend, thisMonth } = o.windows;
149
+ const first = { start: today, end: thisWeekend.end };
150
+ const second = { start: addDays(thisWeekend.end, 1), end: nextWeekend.end };
151
+ const later = { start: addDays(nextWeekend.end, 1), end: thisMonth.end };
152
+ const horizon = { start: today, end: later.start <= later.end ? later.end : second.end };
153
+
154
+ const dated = o.items.filter((i) => i.kind === 'dated' && !isExpired(i, today) && overlapsWindow(i, horizon));
155
+ const underWay = (i: AgendaItem) => lastDay(i) > startDay(i) && startDay(i) <= today;
156
+ const runs = dated.filter(underWay).sort((a, b) => lastDay(a).localeCompare(lastDay(b)) || a.title.localeCompare(b.title));
157
+ const listed = dated.filter((i) => !underWay(i)).sort(byStart);
158
+
159
+ const h = o.headings;
160
+ const spans = [
161
+ { id: 'this-weekend', heading: today < thisWeekend.start ? h.thisWeek ?? h.thisWeekend : h.thisWeekend, w: first },
162
+ { id: 'next-weekend', heading: h.nextWeek ?? h.nextWeekend, w: second },
163
+ ...(later.start <= later.end ? [{ id: 'later', heading: h.later, w: later }] : []),
164
+ ].map((s) => ({ ...s, items: listed.filter(within(s.w)) }));
165
+ const windows: WhatsOnWindow[] = spans.map((s) => ({ id: s.id, heading: s.heading, range: rangeLabel(s.w, locale), days: groupByDay(s.items, o, locale), empty: o.empty }));
166
+
167
+ const minCount = o.minCount ?? 3;
168
+ const thin = o.fallback || [thisWeekend, nextWeekend].some((w) => dated.filter((i) => overlapsWindow(i, w)).length < minCount);
169
+ const regulars = thin ? o.items.filter((i) => i.kind === 'recurring' && !isExpired(i, today) && startDay(i) <= horizon.end) : [];
170
+ return {
171
+ runs: runs.length
172
+ ? { heading: h.runs, items: runs.map((i) => ({ id: i.id, title: i.title, ...target(i), span: rangeLabel({ start: startDay(i), end: lastDay(i) }, locale), venue: i.venue.name, endsOn: lastDay(i) })) }
173
+ : undefined,
174
+ windows,
175
+ regulars: regulars.length
176
+ ? { heading: h.regulars, intro: o.regularsIntro, items: regulars.map((i) => ({ id: i.id, title: i.title, ...target(i), recurrence: i.recurrence ?? '', venue: i.venue.name, endsOn: i.endDate })) }
177
+ : undefined,
178
+ items: [...runs, ...spans.flatMap((s) => s.items), ...regulars],
179
+ };
180
+ }